I was using this code to start parse server 5. I changed the server hardware and installed a new parse server to the new server hardware. I installed latest parse server 6 and this code is not working anymore. What should I change in this code to work again?
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();
var mountPath = '/...';
var api = new ParseServer({
databaseURI: 'mongodb://...',
appId : '...',
masterKey : '...',
serverURL : 'http://127.0.0.1:...',
publicServerURL: '...',
cloud: '...',
allowClientClassCreation: false
});
app.use(mountPath, api);
var port = ...;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server running on port ' + port + '.');
});
The error message I get:
TypeError: Router.use() requires a middleware function but got a Object
at Function.use (/home/ubuntu/parse/node_modules/express/lib/router/index.js:469:13)
at Function.<anonymous> (/home/ubuntu/parse/node_modules/express/lib/application.js:227:21)
at Array.forEach (<anonymous>)
at Function.use (/home/ubuntu/parse/node_modules/express/lib/application.js:224:7)
at Object.<anonymous> (/home/ubuntu/parse/armenianChurches.js:20:5)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Object.<anonymous> (/home/ubuntu/parse/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
Replace
app.use(mountPath, api);byapp.use(mountPath, api.app);Also, you need to add
await api.start();before that point, and if you are running a version of JS that does not support this at the toplevel, either you put it in anasync functionor you doapi.start().then(()=>{ app.use(mountPath, api.app); })instead.After those 2 changes, the server runs; if I only do the 1st thing, the server appears to start, but the client can't do anything.
See https://github.com/parse-community/parse-server/blob/alpha/6.0.0.md
But then, on top of that, it broke masterKey access, due to the
masterKeyIpsfeature, which no longer defaults to accepting all addresses. You may have to configure this.