unpkg/server.js

36 lines
860 B
JavaScript
Raw Normal View History

2018-02-17 00:00:06 +00:00
const path = require("path");
const throng = require("throng");
2018-05-17 17:10:33 +00:00
2018-02-17 00:00:06 +00:00
const createServer = require("./server/createServer");
const createDevServer = require("./server/createDevServer");
2018-05-17 17:10:33 +00:00
const config = require("./server/config");
2017-08-19 06:10:04 +00:00
function startServer(id) {
2018-02-17 00:00:06 +00:00
const server =
process.env.NODE_ENV === "production"
? createServer(
path.resolve(__dirname, "public"),
path.resolve(__dirname, "server/stats.json")
)
: createDevServer(
path.resolve(__dirname, "public"),
require("./webpack.config"),
2018-05-17 17:10:33 +00:00
config.origin
2018-02-17 00:00:06 +00:00
);
2017-08-19 06:10:04 +00:00
2018-05-17 17:10:33 +00:00
server.listen(config.port, () => {
console.log(
"Server #%s listening on port %s, Ctrl+C to stop",
id,
config.port
);
2018-02-17 00:00:06 +00:00
});
2017-08-19 06:10:04 +00:00
}
throng({
workers: process.env.WEB_CONCURRENCY || 1,
2017-08-13 00:23:40 +00:00
lifetime: Infinity,
grace: 25000,
2017-08-19 06:10:04 +00:00
start: startServer
2018-02-17 00:00:06 +00:00
});