forked from parse-community/parse-server-example
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
93 lines (80 loc) · 3.36 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Feb 2023, we tried to upgrade this project to be of type "module" and use import/export instead of require.
// It worked locally, but when we deployed to a real server, the parse server failed to start.
// I never could determine why. So I punted and reverted to using require.
const express = require("express");
const ParseServer = require("parse-server").ParseServer;
const ParseDashboard = require("parse-dashboard");
const BloomFirebaseAuthAdapter = require("./bloomFirebaseAuthAdapter");
const databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log("DATABASE_URI not specified, falling back to localhost.");
}
const serverConfig = {
// Somehow, node 18 causes localhost to try to resolve as IPv6 here which can break things.
// Using 127.0.0.1 instead works around that.
databaseURI: databaseUri || "mongodb://127.0.0.1:27017/dev",
cloud: process.env.CLOUD_CODE_MAIN || __dirname + "/cloud/main.js",
appId: process.env.APP_ID || "myAppId",
masterKey: process.env.MASTER_KEY || "123",
readOnlyMasterKey: process.env.READ_ONLY_MASTER_KEY || "ro",
serverURL: process.env.SERVER_URL || "http://localhost:1337/parse",
appName: process.env.APP_NAME || "BloomLibrary.org",
auth: { bloom: { module: BloomFirebaseAuthAdapter, enabled: true } },
masterKeyIps: process.env.PARSE_SERVER_MASTER_KEY_IPS
? process.env.PARSE_SERVER_MASTER_KEY_IPS.split(",")
: ["127.0.0.1", "::1"],
enforcePrivateUsers: false,
allowClientClassCreation: false,
};
const dashboard = new ParseDashboard({
apps: [
{
appId: serverConfig.appId,
serverURL: serverConfig.serverURL,
masterKey: serverConfig.masterKey,
readOnlyMasterKey: serverConfig.readOnlyMasterKey,
appName: serverConfig.appName,
production: serverConfig.serverURL.includes("production"),
},
],
trustProxy: 1,
users: [
{
user: serverConfig.appId,
pass: serverConfig.masterKey,
},
{
user: "master",
pass: serverConfig.masterKey,
},
{
user: "readonly",
pass: serverConfig.readOnlyMasterKey,
readOnly: true,
},
],
});
const app = express();
// Serve the Parse API on the /parse URL prefix
const mountPath = process.env.PARSE_MOUNT || "/parse";
const server = new ParseServer(serverConfig);
// For an unknown reason, when deployed on a real server, await server.start() causes the server to never successfully start.
server.start().then(() => {
app.use(mountPath, server.app);
// The main thing here is the google-site-verification meta tag.
// This lets us access the site on the Google Search Console.
app.get("/", function (req, res) {
res.status(200).send(
"<html>" +
'<head><meta name="google-site-verification" content="dm8VsqC5uw-fikoD-4ZxYbPfzV-qYyrPCJq7aIgvlJo" /></head>' +
'<body><a href="https://bloomlibrary.org">Bloom Library</a></body>' +
"</html>"
);
});
app.use("/dashboard", dashboard);
const port = process.env.PORT || 1337;
const httpServer = require("http").createServer(app);
httpServer.listen(port, function () {
console.log("bloom-parse-server running on port " + port + ".");
});
});