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-07-31 17:13:26 +00:00
|
|
|
const createServer = require("./modules/createServer");
|
|
|
|
const createDevServer = require("./modules/createDevServer");
|
|
|
|
const serverConfig = require("./modules/serverConfig");
|
2017-03-26 06:53:54 +00:00
|
|
|
|
2018-07-31 17:13:26 +00:00
|
|
|
require("./modules/clientRuntime");
|
2018-07-31 17:07:27 +00:00
|
|
|
|
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"),
|
2018-07-06 00:08:56 +00:00
|
|
|
path.resolve(__dirname, "stats.json")
|
2018-02-17 00:00:06 +00:00
|
|
|
)
|
|
|
|
: createDevServer(
|
|
|
|
path.resolve(__dirname, "public"),
|
|
|
|
require("./webpack.config"),
|
2018-07-31 17:13:26 +00:00
|
|
|
serverConfig.origin
|
2018-02-17 00:00:06 +00:00
|
|
|
);
|
2017-08-19 06:10:04 +00:00
|
|
|
|
2018-07-31 17:13:26 +00:00
|
|
|
server.listen(serverConfig.port, () => {
|
2018-05-17 17:10:33 +00:00
|
|
|
console.log(
|
|
|
|
"Server #%s listening on port %s, Ctrl+C to stop",
|
|
|
|
id,
|
2018-07-31 17:13:26 +00:00
|
|
|
serverConfig.port
|
2018-05-17 17:10:33 +00:00
|
|
|
);
|
2018-02-17 00:00:06 +00:00
|
|
|
});
|
2017-08-19 06:10:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 06:53:54 +00:00
|
|
|
throng({
|
|
|
|
workers: process.env.WEB_CONCURRENCY || 1,
|
2018-08-26 00:35:52 +00:00
|
|
|
start: startServer,
|
2017-08-13 00:23:40 +00:00
|
|
|
lifetime: Infinity,
|
2018-08-26 00:35:52 +00:00
|
|
|
|
2018-08-26 01:19:50 +00:00
|
|
|
// In production, increase throng's default grace period to allow
|
|
|
|
// servers that are still handling requests to finish. Heroku shuts
|
|
|
|
// down processes forcefully after 30 seconds, so exit before that
|
|
|
|
// happens to avoid an exit timeout.
|
2018-08-26 00:35:52 +00:00
|
|
|
// https://devcenter.heroku.com/articles/dynos#shutdown
|
2018-08-26 01:19:50 +00:00
|
|
|
grace: process.env.NODE_ENV === "production" ? 25000 : 5000
|
2018-02-17 00:00:06 +00:00
|
|
|
});
|