mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
00fb4d1af7
- crypto → node:crypto - fs → node:fs - fs/promises → node:fs/promises - path → node:path - http → node:http - https → node:https - stream → node:stream - buffer → node:buffer - url → node:url - os → node:os - net → node:net - dns → node:dns - events → node:events - readline → node:readline - querystring → node:querystring - util → node:util
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import env from "../env";
|
|
|
|
/**
|
|
* Find if SSL certs are available in the environment or filesystem and return
|
|
* as a valid ServerOptions object
|
|
*/
|
|
export function getSSLOptions() {
|
|
function safeReadFile(name: string) {
|
|
try {
|
|
return fs.readFileSync(
|
|
path.normalize(`${__dirname}/../../../${name}`),
|
|
"utf8"
|
|
);
|
|
} catch (_err) {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
try {
|
|
return {
|
|
key:
|
|
(env.SSL_KEY
|
|
? Buffer.from(env.SSL_KEY, "base64").toString("ascii")
|
|
: undefined) ||
|
|
safeReadFile("private.key") ||
|
|
safeReadFile("private.pem") ||
|
|
safeReadFile("server/config/certs/private.key"),
|
|
cert:
|
|
(env.SSL_CERT
|
|
? Buffer.from(env.SSL_CERT, "base64").toString("ascii")
|
|
: undefined) ||
|
|
safeReadFile("public.cert") ||
|
|
safeReadFile("public.pem") ||
|
|
safeReadFile("server/config/certs/public.cert"),
|
|
};
|
|
} catch (_err) {
|
|
return {
|
|
key: undefined,
|
|
cert: undefined,
|
|
};
|
|
}
|
|
}
|