-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (42 loc) · 1.16 KB
/
server.js
File metadata and controls
49 lines (42 loc) · 1.16 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
42
43
44
45
46
47
48
49
/** @format */
import "dotenv/config";
import express from "express";
import fs from "fs";
import https from "https";
import http from "http";
import { handler } from "./build/handler.js";
import { umzug } from "./migrator.js";
let isHttp = false;
process.argv.slice(2).forEach(function (val) {
if (val === "--http" && val !== "--https") {
isHttp = true;
}
});
//Mount umzug database
(async () => {
await umzug.up();
})();
//Launch express server
const app = express();
if (isHttp) {
const HTTP_PORT = 80;
const httpServer = http.createServer(app);
httpServer.listen(HTTP_PORT, function () {
console.info("HTTP Server is running on: http://localhost:%s", HTTP_PORT);
});
} else {
//SSL credentials
var key = fs.readFileSync("./ssl/privkey.pem");
var cert = fs.readFileSync("./ssl/cert.pem");
var credentials = {
key: key,
cert: cert,
};
const httpsServer = https.createServer(credentials, app);
const SSLPORT = 443;
httpsServer.listen(SSLPORT, function () {
console.info("HTTPS Server is running on: https://localhost:%s", SSLPORT);
});
}
// let SvelteKit handle everything else, including serving prerendered pages and static assets
app.use(handler);