-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
113 lines (101 loc) · 3.5 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const express = require("express");
const compression = require("compression");
const ParseServer = require("parse-server").ParseServer;
const { FirebaseAuthAdapter } = require("parse-server-firebase-auth");
const fs = require("fs");
const dotenv = require("dotenv");
const helmet = require("helmet");
const Sentry = require("@sentry/node");
const Tracing = require("@sentry/tracing");
dotenv.config();
var databaseUri = process.env.DATABASE_URI || "";
if (!databaseUri) {
console.log("DATABASE_URI not specified, falling back to localhost.");
}
const port = process.env.PORT || 1337;
const internalPort = process.env.PROD
? process.env.INTERNAL_PORT || 4042
: port;
// Replace the port in the server URL for convenience so that we don't have to change the env file to make it work during both development
// and live deployment
let serverURL = process.env.SERVER_URL || "http://localhost:1337/parse";
if (!process.env.PROD && process.env.SERVER_URL && process.env.INTERNAL_PORT) {
serverURL = process.env.SERVER_URL.replace(
`:${process.env.INTERNAL_PORT}/`,
`:${port}/`,
);
}
let publicServerURL = process.env.PROD
? process.env.PUBLIC_SERVER_URL
: serverURL;
const server = new ParseServer({
auth: {
firebase: new FirebaseAuthAdapter(),
google: {},
},
allowHeaders: ["sentry-trace", "baggage"],
allowClientClassCreation: false,
databaseURI: databaseUri || "mongodb://localhost:27017/dev",
cloud: process.env.CLOUD_CODE_MAIN || __dirname + "/cloud.js",
appId: process.env.APP_ID || "myAppId",
masterKey: process.env.MASTER_KEY || "",
masterKeyIps: ["0.0.0.0/0", "::/0"],
serverURL,
publicServerURL,
fileUpload: {
enableForAuthenticatedUser: true,
fileExtensions: ["txt", "ass", "srt", "vtt", "ssa", "plain"],
},
liveQuery: {
classNames: [],
},
maxUploadSize: "100mb",
logLevel: "error",
});
const app = express();
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
app.use(helmet());
app.use(compression());
async function start() {
await server.start();
var mountPath = process.env.PARSE_MOUNT || "/parse";
// Serve the Parse API on the /parse URL prefix
app.use(mountPath, server.app);
Sentry.init({
dsn: process.env.BACKEND_SENTRY_DSN,
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
new Tracing.Integrations.Express({ app }),
],
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 0.2,
enabled: !!process.env.PROD,
});
if (process.env.PROD) {
let httpsServer = require("https").createServer(
{
key: fs.readFileSync(process.env.SSL_KEY_PATH, "utf8"),
cert: fs.readFileSync(process.env.SSL_CERT_PATH, "utf8"),
},
app,
);
httpsServer.listen(port, function () {
console.log("NekoCap HTTPS server running on port " + port + ".");
});
}
app.use(Sentry.Handlers.errorHandler());
// The HTTP server is used to allow cloud code to make calls to the actual parse instance
// Ideally this will not be exposed by the container.
const httpServer = require("http").createServer(app);
httpServer.listen(internalPort, function () {
console.log("NekoCap server running on port " + internalPort + ".");
});
}
void start();
// // This will enable the Live Query real-time server
// ParseServer.createLiveQueryServer(httpServer);