CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/hub/servers/http.ts
Views: 687
1
// The HTTP(S) server, which makes the other servers
2
// (websocket, proxy, and share) available on the network.
3
4
import { Application } from "express";
5
import { readFileSync } from "fs";
6
import { getLogger } from "../logger";
7
import { createServer as httpsCreateServer } from "https";
8
import { createServer as httpCreateServer } from "http";
9
10
interface Options {
11
cert?: string;
12
key?: string;
13
app: Application;
14
}
15
16
export default function init({ cert, key, app }: Options) {
17
const winston = getLogger("init-http-server");
18
if (key || cert) {
19
if (!key || !cert) {
20
throw Error("specify *both* key and cert or neither");
21
}
22
winston.info("Creating HTTPS server...");
23
return httpsCreateServer(
24
{
25
cert: readFileSync(cert),
26
key: readFileSync(key),
27
},
28
app
29
);
30
} else {
31
winston.info("Creating HTTP server...");
32
return httpCreateServer(app);
33
}
34
}
35
36