We are trying to migrate our iOs app from Parse to AWS. Using Curl we can get to functions but otherwise we get the error. Here is the index.js file, what are we doing wrong. Please advice.
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);
We are trying to migrate our iOs app from Parse to AWS. Using Curl we can get to functions but otherwise we get the error. Here is the index.js file, what are we doing wrong. Please advice.
You have to setup a ExpressJS middleware to allow Parse headers, and then forward the request to the next middleware Parse
, by calling next()
Add the following code before 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();
}