forked from jaredpalmer/react-email-workflow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
42 lines (30 loc) · 878 Bytes
/
server.js
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
"use strict";
const http = require("http");
const logger = require("logfmt");
http.globalAgent.maxSockets = Infinity;
const web = require("./web");
const PORT = process.env.PORT || 3000;
const __DEV__ = process.env.NODE_ENV === "development";
function start() {
logger.log({ type: "info", message: "starting server" });
let server;
process.on("SIGTERM", exit);
function listen() {
const app = web(__DEV__);
server = http.createServer(app);
server.listen(PORT, err => {
if (err) throw err;
logger.log({
type: "info",
message: `running on port ${PORT} in ${process.env.NODE_ENV} mode`,
});
});
}
function exit(reason) {
logger.log({ type: "info", message: "closing server", reason: reason });
if (server) server.close(process.exit.bind(process));
else process.exit();
}
listen();
}
start();