成功推送后发送以下错误可防止发送推送:
0|parse-wr | #### PUSH ERRORReceived an error with invalid JSON from Parse: <html>
0|parse-wr | <head><title>400 Bad Request</title></head>
0|parse-wr | <body bgcolor="white">
0|parse-wr | <center><h1>400 Bad Request</h1></center>
0|parse-wr | <hr><center>nginx/1.10.3 (Ubuntu)</center>
0|parse-wr | </body>
0|parse-wr | </html>
这发生在我改变了我的ubuntu服务器DNS后,这是我的nginx sites-enabled / default
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /mnt/psapp/;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name psappco.ir www.psappco.ir;
location / {
try_files $uri $uri/ =404;
}
# location /test {
# root /mnt/psapp;
# }
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/psappco.ir/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/psappco.ir/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
# Redirect non-https traffic to https
# if ($scheme != "https") {
# return 301 https://$host$request_uri;
# } # managed by Certbot
location /parse/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:1337/parse/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /dashboard/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:4040/dashboard/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
}
client_max_body_size 100M;
}
我应该在nginx中添加与推送适配器相关的东西,我已经使用let encrypt激活了ssl。 nginx版本:nginx / 1.10.3(Ubuntu) 解析服务器版本2.3.8 我用过的云代码是:
Parse.Cloud.define('driveRequest', function(request, response) {
// request has 2 parameters: params passed by the client and the authorized user
var params = request.params;
var user = request.user;
// extract out the channel to send
var action = params.action;
var launch = params.launch;
// use to custom tweak whatever payload you wish to send
var pushQuery = new Parse.Query(Parse.Installation);
var driverQuery = new Parse.Query(Parse.User);
driverQuery.equalTo("isonline",true);
driverQuery.equalTo("riderordriver","driver");
//var nearbyDriversQuery = new Parse.Query(Parse.User);
var riderLocation = new Parse.GeoPoint({latitude: params.riderLatitude, longitude: params.riderLongitude});
driverQuery.withinKilometers("location",riderLocation,2.0);
//var driverQuery = Parse.Query.or(nearbyDriversQuery,isOnlineQuery);
pushQuery.matchesQuery('users',driverQuery);
// pushQuery.matchesQuery('isonlineusers',isOnlineQuery);
var payload = {
"action": action,
"launch": launch,
};
// Note that useMasterKey is necessary for Push notifications to succeed.
Parse.Push.send({
where: pushQuery,
data: payload
}, { success: function() {
console.log("#### PUSH OK");
}, error: function(error) {
console.log("#### PUSH ERROR" + error.message);
},useMasterKey:true});
response.success('success');
});
和ParseServer index.js:
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var ParseDashboard = require('parse-dashboard');
var path = require('path');
var FSStoreAdapter = require('parse-server-fs-store-adapter');
var fs_store_adapter = new FSStoreAdapter({
filesSubDirectory: "/root/parsefiles"
});
//var Parse = require('parse/node').Parse;
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var pushConfig = {};
if (process.env.GCM_SENDER_ID && process.env.GCM_API_KEY) {
pushConfig['android'] = { senderId: process.env.GCM_SENDER_ID || 'my sender id',
apiKey: process.env.GCM_API_KEY || 'my key'};
}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/taxifinder',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'My app_ID',
masterKey: process.env.MASTER_KEY || 'My master key', //Add your master key here. Keep it secret!
push: pushConfig,
filesAdapter: fs_store_adapter,
serverURL: process.env.SERVER_URL || 'https/localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ['Test'],
redisURL: 'redis://localhost:6379'
},
maxUploadSize: "100mb"
});
var app = express();
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// Parse Server plays nicely with the rest of your web routes
//app.get('/', function(req, res) {
// res.status(200).send('I dream of being a website. Please star the parse-server repo on GitHub!');
// res.sendFile(path.join(__dirname, '/public/index.html'));
//});
// There will be a test page available on the /test path of your server url
// Remove this before launching your app
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
ParseServer.createLiveQueryServer(httpServer,{
redisURL: 'redis://localhost:6379'
});
var dashboard = new ParseDashboard({
"apps": [{
"serverURL": 'https://psappco.ir/parse', // Not localhost
"appId": 'my app id',
"masterKey": 'My master key',
"appName": "PSAPP",
"production": false,
"iconName": "app-icon.png",
}],
"users": [
{
"user":"---",
"pass":"----"
}
],
"iconsFolder": "icons"
});
var dashApp = express();
// make the Parse Dashboard available at /dashboard
dashApp.use('/dashboard', dashboard);
// Parse Server plays nicely with the rest of your web routes
dashApp.get('/', function(req, res) {
res.status(200).send('Parse Dashboard App');
});
var httpServerDash = require('http').createServer(dashApp);
httpServerDash.listen(4040, function() {
console.log('dashboard-server running on port 4040.');
});
答案 0 :(得分:0)
这可能是由于您的配置。 SERVER_URL
的价值是多少?它是否包含/parse
?