-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (32 loc) · 1.01 KB
/
server.js
File metadata and controls
41 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { handler } from "./build/handler.js";
import express from "express";
import { readFileSync } from "node:fs";
import http from "node:http";
import https from "node:https";
let hasSSL = false;
let key;
let cert;
if (process.env.HTTPS_CERT_PATH && process.env.HTTPS_KEY_PATH) {
hasSSL = true;
key = readFileSync(process.env.HTTPS_KEY_PATH);
cert = readFileSync(process.env.HTTPS_CERT_PATH);
}
const app = express();
const host = process.env.HOST_NAME;
if (hasSSL) {
const httpsServer = https.createServer({ key, cert }, app);
httpsServer.listen(3000, host, function () {
console.log("HTTPS Server is running on: https://%s:3000", host);
});
} else {
const httpServer = http.createServer(app);
httpServer.listen(3000, host, function () {
console.log("HTTP Server is running on: http://%s:3000", host);
});
}
app.use((req, res, next) => {
const d = new Date();
console.log(`(${d.toLocaleString()}) ${req.socket.remoteAddress} [${req.method}] ${req.url}`);
next();
});
app.use(handler);