mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-13 02:00:10 +01:00
Patch WSS upgrade for manual HTTPS certs (#1429)
* Patch WSS upgrade for manual HTTPS certs * update comment * refactor
This commit is contained in:
parent
cae6cee1b5
commit
f140139534
5
server/.gitignore
vendored
5
server/.gitignore
vendored
@ -18,4 +18,7 @@ public/
|
|||||||
# For legacy copies of repo
|
# For legacy copies of repo
|
||||||
documents
|
documents
|
||||||
vector-cache
|
vector-cache
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
|
|
||||||
|
# Local SSL Certs for HTTPS
|
||||||
|
sslcert
|
@ -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);
|
app.use("/api", apiRouter);
|
||||||
systemEndpoints(apiRouter);
|
systemEndpoints(apiRouter);
|
||||||
extensionEndpoints(apiRouter);
|
extensionEndpoints(apiRouter);
|
||||||
@ -109,8 +114,6 @@ app.all("*", function (_, response) {
|
|||||||
response.sendStatus(404);
|
response.sendStatus(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!!process.env.ENABLE_HTTPS) {
|
// In non-https mode we need to boot at the end since the server has not yet
|
||||||
bootSSL(app, process.env.SERVER_PORT || 3001);
|
// started and is `.listen`ing.
|
||||||
} else {
|
if (!process.env.ENABLE_HTTPS) bootHTTP(app, process.env.SERVER_PORT || 3001);
|
||||||
bootHTTP(app, process.env.SERVER_PORT || 3001);
|
|
||||||
}
|
|
||||||
|
@ -12,16 +12,18 @@ function bootSSL(app, port = 3001) {
|
|||||||
const privateKey = fs.readFileSync(process.env.HTTPS_KEY_PATH);
|
const privateKey = fs.readFileSync(process.env.HTTPS_KEY_PATH);
|
||||||
const certificate = fs.readFileSync(process.env.HTTPS_CERT_PATH);
|
const certificate = fs.readFileSync(process.env.HTTPS_CERT_PATH);
|
||||||
const credentials = { key: privateKey, cert: certificate };
|
const credentials = { key: privateKey, cert: certificate };
|
||||||
|
const server = https.createServer(credentials, app);
|
||||||
|
|
||||||
https
|
server
|
||||||
.createServer(credentials, app)
|
|
||||||
.listen(port, async () => {
|
.listen(port, async () => {
|
||||||
await setupTelemetry();
|
await setupTelemetry();
|
||||||
new CommunicationKey(true);
|
new CommunicationKey(true);
|
||||||
console.log(`Primary server in HTTPS mode listening on port ${port}`);
|
console.log(`Primary server in HTTPS mode listening on port ${port}`);
|
||||||
})
|
})
|
||||||
.on("error", catchSigTerms);
|
.on("error", catchSigTerms);
|
||||||
return app;
|
|
||||||
|
require("express-ws")(app, server); // Apply same certificate + server for WSS connections
|
||||||
|
return { app, server };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(
|
console.error(
|
||||||
`\x1b[31m[SSL BOOT FAILED]\x1b[0m ${e.message} - falling back to HTTP boot.`,
|
`\x1b[31m[SSL BOOT FAILED]\x1b[0m ${e.message} - falling back to HTTP boot.`,
|
||||||
@ -46,7 +48,8 @@ function bootHTTP(app, port = 3001) {
|
|||||||
console.log(`Primary server in HTTP mode listening on port ${port}`);
|
console.log(`Primary server in HTTP mode listening on port ${port}`);
|
||||||
})
|
})
|
||||||
.on("error", catchSigTerms);
|
.on("error", catchSigTerms);
|
||||||
return app;
|
|
||||||
|
return { app, server: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
function catchSigTerms() {
|
function catchSigTerms() {
|
||||||
|
Loading…
Reference in New Issue
Block a user