forked from parse-community/parse-server-example
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
45 lines (36 loc) · 1.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Example express application adding the parse-server module to expose Parse
// compatible API routes.
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var ParseDashboard = require('parse-dashboard');
var parseServerConfig = require('parse-server-config');
var url = require('url');
var path = require('path');
var config = parseServerConfig(__dirname);
// Modify config as necessary before initializing parse server & dashboard
var app = express();
app.use('/public', express.static(__dirname + '/public'));
app.use('/parse', new ParseServer(config.server));
app.use('/parse-dashboard', ParseDashboard(config.dashboard, true));
app.listen(process.env.PORT || url.parse(config.server.serverURL).port, function () {
console.log(`Parse Server running at ${config.server.serverURL}`);
});
// Force https for security. Remove the following block if you want to allow http access
app.use(function(req, res, next) {
if (req.headers['x-forwarded-proto'] == 'http') {
res.redirect('https://' + req.headers.host + req.path);
} else {
return next();
}
});
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('Make sure to 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'));
});
// This will enable the Live Query real-time server
// ParseServer.createLiveQueryServer(httpServer);