forked from nextstrain/auspice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
58 lines (48 loc) · 2.05 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* eslint no-console: off */
const path = require("path");
const express = require("express");
const expressStaticGzip = require("express-static-gzip");
const charon = require("./src/server/charon");
const globals = require("./src/server/globals");
/* documentation in the static site! */
const devServer = process.argv.indexOf("dev") !== -1;
globals.setGlobals({
localData: process.argv.indexOf("localData") !== -1
});
/* if we are in dev-mode, we need to import specific libraries & set flags */
let webpack, config, webpackDevMiddleware, webpackHotMiddleware;
if (devServer) {
webpack = require("webpack"); // eslint-disable-line
config = require("./webpack.config.dev"); // eslint-disable-line
webpackDevMiddleware = require("webpack-dev-middleware"); // eslint-disable-line
webpackHotMiddleware = require("webpack-hot-middleware"); // eslint-disable-line
}
const app = express();
app.set('port', process.env.PORT || 4000);
if (devServer) {
const compiler = webpack(config);
app.use(webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(webpackHotMiddleware(compiler));
} else {
app.use("/dist", expressStaticGzip("dist"));
app.use(express.static(path.join(__dirname, "dist")));
}
/* redirect www.nextstrain.org to nextstrain.org */
app.use(require('express-naked-redirect')({reverse: true}));
app.get("/favicon.png", (req, res) => {
res.sendFile(path.join(__dirname, "favicon.png"));
});
charon.applyCharonToApp(app);
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
});
const server = app.listen(app.get('port'), () => {
console.log("-----------------------------------");
console.log("Auspice server started on port " + server.address().port);
console.log(devServer ? "Serving dev bundle with hot-reloading enabled" : "Serving compiled bundle from /dist");
console.log(global.LOCAL_DATA ? "Data is being sourced from /data" : "Dataset JSONs are being sourced from S3, narratives via the static github repo");
console.log("-----------------------------------\n\n");
});