at WebSocket.socket.onerror in LiveQueryClient.js when start app - javascript

I have a problem with my small demo for live query as in attached image.
To be honest, I have no idea why does it go wrong. Try to find some solutions around but not yet successfully. Please give me some ideas or solutions if you know this issue. Thanks so much.
Parse server example: 1.4.0
Parse JS SDK: 1.10.2
NodeJS: 8.9.1
npm: 5.5.1
P/S: I have added classes for supporting by Live Query already.
Here is the source which run successfully without using Live Query
Link to src with removed parse link:
var Parse = require('parse/node');
Parse.initialize("shetei5aeJ9Aequi6deejojiv7foh6Hieg2eesh9keingohw");
Parse.serverURL = 'serURLhere';
var Node = Parse.Object.extend('Node');
var q = new Parse.Query('Node');
var subscription = q.subscribe();
var procEventOpen = () => {
console.log('subscription opened...');
};
subscription.on('open', procEventOpen);

This happened to me when I had a typo in server url.
Try to explicit specify liveQueryServerURL parameter:
Parse.liveQueryServerURL = 'ws://yourserverurl/parse';
Note the ws instead of http(s)

Related

Extracting Pure Javascript from NodeJS project [duplicate]

I don't know how to get a javascript file to work for web-browser functionalit, when it's coded as node.js.
The code in question is from a github graphenejs-lib. I want to convert this node.js code into js:
import {Apis} from "graphenejs-ws";
var {ChainStore} = require("graphenejs-lib");
Apis.instance("wss://bitshares.openledger.info/ws", true).init_promise.then((res) => {
console.log("connected to:", res[0].network);
ChainStore.init().then(() => {
ChainStore.subscribe(updateState);
});
});
let dynamicGlobal = null;
function updateState(object) {
dynamicGlobal = ChainStore.getObject("2.1.0");
console.log("ChainStore object update\n", dynamicGlobal ? dynamicGlobal.toJS() : dynamicGlobal);
}
There is another github from the same developer, steemjs-lib, that shows both the node.js use, and the browser use in the README default page.
I don't know how to make graphenejs-lib into browser javascript, like the steemjs-lib has been made into a regular javascript working version. I contact the dev, but have yet to receive a response.
I figured other people actually know how to do what the dev did for steemjs-lib, and get the graphenejs-lib to work in a browser.
Can you help me out? Thank you.
You can use Browserify to help you with that:
Note that not all of the Node's APIs will be available in the browser.
Use browserify. https://wzrd.in/ will package it for you if you just want to use that one library. https://wzrd.in/standalone/graphenejs-lib#latest
<script src="https://wzrd.in/standalone/graphenejs-lib#latest"></script>
<script>
const {ChainStore} = graphenejsLib;
...
</script>

Java and Javascript - Lastmodified on Linux

I wrote a script on the Jmeter Web Driver in javascript and Java .
On a Windows system , the script is running perfectly . But on a Linux System , i have a weird problem . The lastmodifed then i obtain is not good. front_end.jtl has been modified yesterday , but the script say today at 10:00 in milliseconds timestamp .
Please help me.
// Importing packages (and all classes in package) from Java into Javascript var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
// We don't use wait in this very simple test, but here is way to access for more realistic testing
var wait=new support_ui.WebDriverWait(WDS.browser, 5)
// Start recording the time for this request
WDS.sampleResult.sampleStart();
// Let's get a page
var baseUrl = "cnyw${FE}.mycore.core-cloud.net"
WDS.browser.get("https://"+ baseUrl)
var frontjtl = new java.io.File('/home/mycore/front_end.jtl')
var frontlog = new java.io.File('/home/mycore/jmeter_front_end.log')
var lastmodifjtl = frontjtl.lastModified()
var lastmodiflog = frontlog.lastModified()
if ( lastmodifjtl = lastmodiflog ) {
var screenshot = WDS.browser.getScreenshotAs(pkg.OutputType.FILE)
screenshot.renameTo(new java.io.File('/home/mycore/screenshots/tools/screenshot_cnyw${FE}.png'))
}
// Record the time of the request
WDS.sampleResult.sampleEnd();
I would recommend using Files.getLastModifiedTime() instead, something like:
var lastmodifjtl = java.nio.file.Files.getLastModifiedTime(java.nio.file.Paths.get(frontjtl.toURI()))
should do the trick for you.
Just in case see The WebDriver Sampler: Your Top 10 Questions Answered article for more information
I found an explanation : https://bugs.openjdk.java.net/browse/JDK-8177809
It's a confirmed bug ...
i have rewrite the script in Java directly. All is okay now.

How to wrap node express output so that it can be included as javascript?

Trying to modify node.js express to wrap the standard output in javascript (utilising document.write) so that I can include it into other HTML files. I want to encode the output at the express level and decode it at the client.
Edit: I want to create a standard node app that generates HTML output but wrap it just before sending with the javascript. This is so I can continue to utilise express-handlebars and other add ons without disruption to the output.
If this is already a thing in node please point me to documentation on how to achieve it? Otherwise I'm looking for where to change the code in express to wrap each output.
For clarity; to answer please include a reference the correct express file(s) and start with existing code to produce a modified version that achieves my goal.
The Express version I am looking at is 4.15.4. I've viewed the code and found the index.js and route.js files (https://github.com/expressjs/express/tree/master/lib/router) but don't understand enough to know where to modify the code.
Example
My initial goal would be for my node app to return encoded HTML wrapped in code similar to the following:
var str = "<encoded content goes here>";
document.write(decodeURI(str));
Example way to call my node from HTML:
<script src='http://localhost:3000/'></script>
Feel free to comment on the approach if you have an opinion.
Thanks!
I think I worked it out.
In file https://github.com/expressjs/express/blob/master/lib/response.js # line 116 I added the following code:
chunk = "str = \""+encodeURI(body)+"\";\ndocument.write(decodeURI(str));\n";
Seems to have worked.
So:
res.send = function send(body) {
var chunk = body;
var encoding;
var len;
var req = this.req;
var type;
// settings
var app = this.app;
<added my code here>
// allow status / body

Scraping authenticated website in node.js

I want to scrape my college website (moodle) with node.js but I haven't found a headless browser able to do it. I have done it in python in just 10 lines of code using RoboBrowser:
from robobrowser import RoboBrowser
url = "https://cas.upc.edu/login?service=https%3A%2F%2Fatenea.upc.edu%2Fmoodle%2Flogin%2Findex.php%3FauthCAS%3DCAS"
browser = RoboBrowser()
browser.open(url)
form = browser.get_form()
form['username'] = 'myUserName'
form['password'] = 'myPassword'
browser.submit_form(form)
browser.open("http://atenea.upc.edu/moodle/")
print browser.parsed
The problem is that the website requires authentication. Can you help me? Thanks!
PD: I think this can be useful https://www.npmjs.com/package/form-scraper but I can't get it working.
Assuming you want to read a 3rd party website, and 'scrape' particular pieces of information, you could use a library such as cheerio to achieve this in Node.
Cheerio is a "lean implementation of core jQuery designed specifically for the server". This means that given a String representation of a DOM (or part thereof), cheerio can traverse it in much the same way as jQuery can.
An example from Max Ogden show how you can use the request module to grab HTML from a remote server and then pass it to cheerio:
var $ = require('cheerio')
var request = require('request')
function gotHTML(err, resp, html) {
if (err) return console.error(err)
var parsedHTML = $.load(html)
// get all img tags and loop over them
var imageURLs = []
parsedHTML('a').map(function(i, link) {
var href = $(link).attr('href')
if (!href.match('.png')) return
imageURLs.push(domain + href)
})
}
var domain = 'http://substack.net/images/'
request(domain, gotHTML)
Selenium has support for multiple languages and multiple platforms and multiple browsers.

The subject content is undefined

I have a small problem using mailparser. When I'm trying to see the subject content it says that is undefined.
My code looks something like this :
var fs = require("fs");
var socket = fs.createWriteStream('./outputmail.eml');
socket.on("end",function()
{
connection.loginfo("end------->");
});
connection.transaction.message_stream.pipe(socket, {}); // haraka related
var mailparser = new MailParser();
mailparser.on("end", function(mail_object){
connection.loginfo("----------SUBJECT-------------------->:", mail_object.subject);
});
fs.createReadStream("./outputmail.eml").pipe(mailparser);
I'm using mailparser in Haraka (http://haraka.github.io) . The whole point doing this, is that I want to parse every mail I receive and add a banner/image/whatever into the mail's body. If you have any idea why this message appears , please let me know.
If that is the code it is likely that you start reading the file before it is written. As the libraries both support streams you should be able to pipe the message_stream directly to mailparser, ie.
var mailparser = new MailParser();
mailparser.on("end", function(mail_object) {
console.log(mail_object);
});
connection.transaction.message_stream.pipe(mailparser, {});
Another reason could naturally be that there just isn't a subject in the email.

Categories

Resources