θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public/
# For legacy copies of repo
documents
vector-cache
yarn-error.log
yarn-error.log

# Local SSL Certs for HTTPS
sslcert
15 changes: 9 additions & 6 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ app.use(
})
);

require("express-ws")(app);
if (!!process.env.ENABLE_HTTPS) {
bootSSL(app, process.env.SERVER_PORT || 3001);
} else {
require("express-ws")(app); // load WebSockets in non-SSL mode.
}

app.use("/api", apiRouter);
systemEndpoints(apiRouter);
extensionEndpoints(apiRouter);
Expand Down Expand Up @@ -109,8 +114,6 @@ app.all("*", function (_, response) {
response.sendStatus(404);
});

if (!!process.env.ENABLE_HTTPS) {
bootSSL(app, process.env.SERVER_PORT || 3001);
} else {
bootHTTP(app, process.env.SERVER_PORT || 3001);
}
// In non-https mode we need to boot at the end since the server has not yet
// started and is `.listen`ing.
if (!process.env.ENABLE_HTTPS) bootHTTP(app, process.env.SERVER_PORT || 3001);
11 changes: 7 additions & 4 deletions server/utils/boot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ function bootSSL(app, port = 3001) {
const privateKey = fs.readFileSync(process.env.HTTPS_KEY_PATH);
const certificate = fs.readFileSync(process.env.HTTPS_CERT_PATH);
const credentials = { key: privateKey, cert: certificate };
const server = https.createServer(credentials, app);

https
.createServer(credentials, app)
server
.listen(port, async () => {
await setupTelemetry();
new CommunicationKey(true);
console.log(`Primary server in HTTPS mode listening on port ${port}`);
})
.on("error", catchSigTerms);
return app;

require("express-ws")(app, server); // Apply same certificate + server for WSS connections
return { app, server };
} catch (e) {
console.error(
`\x1b[31m[SSL BOOT FAILED]\x1b[0m ${e.message} - falling back to HTTP boot.`,
Expand All @@ -46,7 +48,8 @@ function bootHTTP(app, port = 3001) {
console.log(`Primary server in HTTP mode listening on port ${port}`);
})
.on("error", catchSigTerms);
return app;

return { app, server: null };
}

function catchSigTerms() {
Expand Down