XMLHttpRequest 失败:"Unable to connect to the Parse API"' } } 代码=141,代码=100

XMLHttpRequest failed: "Unable to connect to the Parse API"' } } code=141, code=100

我们正在尝试将我们的 iOs 应用程序从 Parse 迁移到 AWS。使用 Curl 我们可以得到函数,否则我们会得到错误。这是 index.js 文件,我们做错了什么。请指教

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI || 'mongodb://xxxxxxxxxx';

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}
var S3Adapter = require('parse-server').S3Adapter;

var api = new ParseServer({
  //databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  databaseURI: databaseUri || 'xxxxx',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'xxxxx',
  masterKey: process.env.MASTER_KEY || 'xxxxxx', //Add your master key here. Keep it secret!
  fileKey: process.env.FILE_KEY || 'xxxxx',
  //restAPIKey: process.env.REST_API_KEY || 'xxxx',
  javascriptKey: process.env.JAVASCRIPT_KEY || 'xxxxx',
  serverURL: process.env.SERVER_URL || 'http://parseserver-2uxxxxx.elasticbeanstalk.com/',  // Don't forget to change to https if needed
  filesAdapter: new S3Adapter(
    "xxxxxx",
    "xxxxxxxx",
    "xxxxx",
    {directAccess: true}
  ),
  liveQuery: {
    classNames: ["xxx", "xxx", "xxxxx", "xxx"] // List of classes to support for query subscriptions
  }
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

var app = express();

// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));

// 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!');
});

// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
  res.sendFile(path.join(__dirname, '/public/test.html'));
});

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 + '.');
});

// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);

我们正在尝试将我们的 iOs 应用程序从 Parse 迁移到 AWS。使用 Curl 我们可以得到函数,否则我们会得到错误。这是 index.js 文件,我们做错了什么。请指教

Post 请使用您使用的 curl 命令。它匹配 http://parseserver-2uxxxxx.elasticbeanstalk.com 吗?好像不对。

您必须设置一个 ExpressJS 中间件以允许解析 headers,然后通过调用 next()

将请求转发到下一个中​​间件 Parse

app.use(mountPath, api);前添加如下代码:

app.use(function (req, res, next) {

    res.set({ // since there is no res.header class in Parse, we use the equivalent to set the response headers
        'Access-Control-Allow-Origin': '*/*',
        'Access-Control-Allow-Credentials': true,
        'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
        'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, X-Parse-Session-Token'
    });
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    res.header('Access-Control-Allow-Methods','GET, POST, PUT, DELETE, OPTIONS');
    res.header('Access-Control-Allow-Headers','Origin, X-Requested-With, Content-Type, Accept, X-Parse-Session-Token');

    next();
}