-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
105 lines (87 loc) · 2.51 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
const path = require("path");
const express = require("express");
const cors = require("cors");
const { default: ParseServer, ParseGraphQLServer } = require("parse-server");
const config = require("../config");
const initializeServer = require("./initialize-server");
const initializeCMS = require("../cms/initialize-cms");
const createDashboard = require("./dashboard");
if (!config.databaseURI) {
console.log("DATABASE_URI not specified, falling back to localhost.");
}
const {
appId,
mountPath,
publicServerURL,
startLiveQueryServer,
mountGraphQL,
graphQLPath,
} = config;
const {
host,
port,
dashboardEnabled,
dashboardPath,
cmsEnabled,
chiselCmsDistPath,
} = config.extraConfig;
const app = express();
app.use(cors());
const parseServer = new ParseServer(config);
app.use("/public", express.static(path.join(__dirname, "../public")));
app.use(mountPath, parseServer.app);
if (mountGraphQL) {
const parseGraphQLServer = new ParseGraphQLServer(parseServer, {
graphQLPath,
});
parseGraphQLServer.applyGraphQL(app);
}
if (dashboardEnabled) {
const dashboard = createDashboard(config);
app.use(dashboardPath, dashboard);
}
if (cmsEnabled) {
app.use("/", express.static(path.resolve(__dirname, chiselCmsDistPath)));
app.get("/chisel-config.json", (req, res) => {
const response = {
configServerURL: publicServerURL,
configAppId: appId,
};
return res.json(response);
});
app.use("/*", (req, res) =>
res.sendFile(path.resolve(__dirname, chiselCmsDistPath, "index.html"))
);
}
const httpServer = require("http").createServer(app);
if (startLiveQueryServer) {
ParseServer.createLiveQueryServer(httpServer);
}
httpServer.listen(port, async () => {
await initializeServer(config);
await initializeCMS(config);
const serverUrl = port === 443 ? `${host}` : `${host}:${port}`;
console.log(`Parse server is running on https://${serverUrl}${mountPath}`);
if (startLiveQueryServer) {
console.log(`Live Query server is enabled`);
} else {
console.log(`Live Query server is disabled`);
}
if (mountGraphQL) {
console.log(
`GraphQl server is running on https://${serverUrl}${graphQLPath}`
);
} else {
console.log(`GraphQl server is disabled`);
}
if (dashboardEnabled) {
console.log(`Dashboard is enabled on https://${serverUrl}${dashboardPath}`);
} else {
console.log(`Dashboard is disabled`);
}
if (cmsEnabled) {
console.log(`CMS is enabled on https://${serverUrl}`);
} else {
console.log(`CMS is disabled`);
}
});