Push via parse server cloud code: Url not found - parse-platform

After working with Parse for a considerable time on multiple project I recently started moving data to a local Parse server and writing a sample app to get familiar with the system. I managed to get most working so far including Push using het Parse Dashboard.
Unfortunately I can't seem to get Parse Push to work using cloud code.
This is my code:
Parse.Cloud.define('push', function(req, res) {
var logMessage = "Push test";
console.log(logMessage);
var pushQuery = new Parse.Query(Parse.Installation);
Parse.Push.send({
where: pushQuery,
data: {
alert: 'Test'
}
}, {
useMasterKey: true,
success: function() {
// Push sent, send re
res.success('Push Sent');
var logMessage = "Push Sent!";
console.log(logMessage);
},
error: function(error) {
res.error(error)
var logMessage = error;
console.log(logMessage);
// There was a problem :(
}
});
var logMessage = "Push should be sent.";
console.log(logMessage);
});
Unfortunately no push is sent and the following error message is returned:
{
code: 107,
message: 'Received an error with invalid JSON from Parse: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL /push was not found on this server.</p>\n<hr>\n<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address>\n</body></html>\n' }
It seems to indicate the push request is sent to the /push directory of the main server, however I have no clue how I can change this to the appropriate location and I presumed parse-server would automatically choose the right path.
I hope someone might know how to fix this because I'm out of ideas at the moment..

For all that deal with this same issue, here is the solution.
Thanks to Anbarasi for the correct answer. My server settings were incorrect. Upon changing the server URL to the correct settings (address + port) everything started working!

Related

AWS Textract does not run callback in error free run of analyzeDocument

CURRENTLY
I am trying to get AWS Textract working on a Lambda function and am following documentation on https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Textract.html#analyzeDocument-property
My Lambda code:
"use strict";
const AWS = require("aws-sdk");
exports.handler = async (event) => {
let params = JSON.parse(event.body);
console.log("Parse as document...");
let textract = new AWS.Textract();
let doc = params["doc"];
let config = {
Document: {
Bytes: doc,
}
};
textract.analyzeDocument(config, function (err, data) {
console.log("analyzing..."); //<-- nothing logged to console if no error
if (err) {
console.log(err, err.stack);
}
// an error occurred
else {
console.log("data:" + JSON.stringfy(data)); //<-- nothing logged to console if no error
} // successful response
});
console.log("Finished parsing as document.");
};
ISSUE
I cannot get the data back from Textract. It seems I am unable to get the callback working entirely. What's odd is if there is an error e.g. my configuration is wrong, the error handling of the callback will print the log and "analyzing..." log, but without error, none of the logs in the callback print.
Current Logs:
Parse as document...
Finished parsing as document.
Expected / Desired Logs:
Parse as document...
analyzing...
data:{textract output}
Finished parsing as document.
Please help!
NOTES
I am using a role for that Lambda that allows it to access Textract.
I get the same result whether I include the HumanLoopConfig settings or not.
Solved, apparently I needed to setup a promise:
let data = await textract.analyzeDocument(config).promise()
console.log("data:"+data );
console.log("Finished parsing as document.")

Svelte/Sveltekit and socket.io-client not working in dev (works in preview)

I'm trying to make socket.io-client work in a svelte front end app to talk to an existing API server that already uses socket.io. After a number of challenges, I managed to make this work but I can only get this to work with sveltekit's preview and not in dev mode. Wondered if someone with some knowledge of those could explain why or suggest what I need to do to get it connecting in dev?
svelte 3.34.0
sveltekit next-169
socket.io(-client) 4.2.0
basic code as follows, currently within a file $lib/db.js where I define a few stores that are pulled into the layout for general use..
import { io } from "socket.io-client";
import { browser } from '$app/env';
const initSocket = async () => {
console.log('creating socket...');
let socket = io('http://192.168.1.5:4000', { 'connect timeout': 5000 });
socket.on("connect", () => {
// always works in preview...
console.log('socket created with ID:', socket.id);
});
socket.on("connect_error", (error) => {
// permanently fired in dev...
console.error('Failed to connect', error);
});
socket.on("error", (error) => {
console.error('Error on socket', error);
});
socket.on("foo", data => {
// works in preview when server emits a message of type 'foo'..
console.log("FOO:", data);
});
};
if (browser) {
initSocket();
}
// stores setup and exports omitted..
with svelte-kit preview --host I see the socket creation log message with the socket ID and the same can be seen on the api server where it logs the same ID. The socket works and data is received as expected.
with svelte-kit dev --host however, the log message from socket.on("connect").. is never output and I just see an endless stream of error messages in the browser console from the socket.on("connect_error").. call..
Failed to connect Error: xhr poll error
at XHR.onError (transport.js:31)
at Request.<anonymous> (polling-xhr.js:93)
at Request.Emitter.emit (index.js:145)
at Request.onError (polling-xhr.js:242)
at polling-xhr.js:205
Importantly, there is no attempt to actually contact the server at all. The server never receives a connection request and wireshark/tcpdump confirm that no packet is ever transmitted to 192.168.1.5:4000
Obviously having to rebuild and re-run preview mode on each code change makes development pretty painful, does anyone have insight as to what the issue is here or suggestions on how to proceed?
I've had a similar problem, I solved it by adding this code to svelte.config.js:
const config = {
kit: {
vite: {
resolve: {
alias: {
"xmlhttprequest-ssl": "./node_modules/engine.io-client/lib/xmlhttprequest.js",
},
},
},
},
};
The solution was provided by this comment from the vite issues.

Parse Cloud Code Queries do not return anything ever

I have some parse cloud code im running on my self hosted server but im running into an issue where queries are not doing anything. I can run commands through terminal and get data back but when I run a query.find.. nothing happens. For Example:
Parse.Cloud.job("getall", function(request, response) {
var itemStatus = Parse.Object.extend('MovieStatus');
var query = new Parse.Query(itemStatus);
query.find({
success: function(results) {
console.log(results.length)
response.success(results.length);
},
error: function(err) {
response.error(err);
},
useMasterKey : true
})
})
Nothing happens. No error no response. I have added console logs to make sure its at least getting called and it is, but for some reason nothing every returns from the server when I do query.find
I have tried all sorts of things to figure out what the issue is but this affects all of my cloud code so it has to be something in there.
You are using an old syntax. Since version 3.0, Parse Server supports async/await style. Try this:
Parse.Cloud.job("getall", async request => {
​const { log, message } = request;
const ItemStatus = Parse.Object.extend('MovieStatus');
const query = new Parse.Query(ItemStatus);
const results = await query.find({ useMasterKey: true });
log(response.length);
message(response.length);
})
Not this is a job and not a cloud code function. You can invoke this job using Parse Dashboard and you should see the message in the job status section.

reCAPTCHA timing out on verify

Having made no changes (but also not tested this in a couple months), my reCAPTCHA code is timing out when trying to verify the user response (both on localhost and on our DEV server). The IP is rotating in the error message (216.58.218.228:443, 172.217.1.4:443, others). I would normally think that this is a firewall issue - I can't telnet to the IP/Port combinations in the error messages - but I can pull up https://www.google.com/recaptcha/api/siteverify in a browser and get an error response back quickly. Any ideas on what might be going on?
Code I normally use:
// Prepare input.
var input = new NameValueCollection
{
{ "response", captcha },
{ "secret", _settings.SecretKey }
};
// Make call.
byte[] response;
using (WebClient client = new WebClient())
{
response = client.UploadValues(_settings.VerificationUrl, Http.Verbs.POST, input);
}
// Parse response.
var body = Encoding.UTF8.GetString(response);
var result = JsonConvert.DeserializeObject<VerificationResponse>(body);
return result.Success;
Attempt at verifying through GET (as recommended here):
using (WebClient client = new WebClient())
{
var response = client.DownloadString($"https://www.google.com/recaptcha/api/siteverify?secret={_settings.SecretKey}&response={captcha}");
}
Example full error message:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 216.58.218.228:443

onIncomingMessage on Sinch-rtc never gets called on receiving Sinch IM message

I am using NodeJS and Sinch-RTC (for IM feature) and I am unable to receive IM messages on my server - Meaning my onIncomingMessage is never called even though a message is sent to my username via phone. I am using the following code on my server.
var SinchClient = require('sinch-rtc');
var sinchClient = new SinchClient({
applicationKey: 'MY-APP-KEY',
capabilities: {messaging: true, calling: true},
supportActiveConnection: true,
});
var messageClient = sinchClient.getMessageClient();
sinchClient.start({username: 'MY_USERNAME', password: 'MY_PASSWORD'}).then(function() {
console.log('Success!');
global_username = username;
}).fail(handleFail)
var handleFail = function() {console.log("Message Sending failed");};
var eventListener = {
onIncomingMessage: function(message) {
console.log( message.textBody);
}
}
messageClient.addEventListener(eventListener);
When I run this program as "node sinchReceive.js" I am unable to receive any sinch message sent to MY_USERNAME. However, I can send a message to a different username and that doesn't have any problem. Please tell me what could be wrong or if I am missing something. Thanks.

Resources