MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / setupHttp

Function setupHttp

panel/src/app.ts:31–71  ·  view source on GitHub ↗
(
  koaApp: Koa,
  ssl: boolean,
  sslPemPath: string,
  sslKeyPath: string,
  port: number,
  host?: string
)

Source from the content-addressed store, hash-verified

29}
30
31function setupHttp(
32 koaApp: Koa,
33 ssl: boolean,
34 sslPemPath: string,
35 sslKeyPath: string,
36 port: number,
37 host?: string
38) {
39 let httpServer: http.Server | https.Server;
40
41 if (ssl) {
42 const options = {
43 cert: fs.readFileSync(path.join(sslPemPath)),
44 key: fs.readFileSync(path.join(sslKeyPath))
45 };
46 httpServer = https.createServer(options, koaApp.callback());
47 } else {
48 httpServer = http.createServer(koaApp.callback());
49 }
50
51 httpServer.on("error", (err) => {
52 logger.error($t("TXT_CODE_app.httpSetupError"));
53 logger.error(err);
54 process.exit(1);
55 });
56
57 httpServer.listen(port, host);
58 logger.info("==================================");
59 logger.info($t("TXT_CODE_app.panelStarted"));
60 logger.info($t("TXT_CODE_app.reference"));
61 let appHost = $t("TXT_CODE_app.host", { port });
62 if (ssl) appHost = appHost.replace("http", "https");
63 logger.info(appHost);
64 logger.info($t("TXT_CODE_app.portTip", { port }));
65 logger.info($t("TXT_CODE_app.exitTip", { port }));
66 logger.info("==================================");
67
68 if (os.platform() == "win32" && hasParams("--open")) {
69 open(ssl ? `https://localhost:${port}/` : `http://localhost:${port}/`);
70 }
71}
72
73async function processExit() {
74 try {

Callers 1

mainFunction · 0.85

Calls 6

$tFunction · 0.90
hasParamsFunction · 0.85
onMethod · 0.80
errorMethod · 0.80
infoMethod · 0.80
exitMethod · 0.45

Tested by

no test coverage detected