gpt4 book ai didi

node.js - XMLHttpRequest 失败 : "Unable to connect to the Parse API"' } } code=141, 代码=100

转载 作者:太空宇宙 更新时间:2023-11-03 23:30:00 24 4
gpt4 key购买 nike

我们正在尝试将我们的 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 文件,我们做错了什么。请指教。

最佳答案

您必须设置一个 ExpressJS 中间件以允许解析 header ,然后通过调用 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();
}

关于node.js - XMLHttpRequest 失败 : "Unable to connect to the Parse API"' } } code=141, 代码=100,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39338540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com