Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local data sans dev server #589

Merged
merged 3 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
"postinstall": "npm run create-data-dir",
"clean": "rimraf dist",
"server": "node server.dist.js",
"server:local": "node server.dist.js localData",
"build": "npm run clean && npm run build:client && npm run build:server",
"build:client": "NODE_ENV=production BABEL_ENV=production webpack --config webpack.config.prod.js",
"build:client:perf": "NODE_ENV=production BABEL_ENV=productiontiming webpack --config webpack.config.prod.js",
"build:electron": "NODE_ENV=production BABEL_ENV=production webpack --config webpack.config.electron.js",
"build:server": "NODE_ENV=production BABEL_ENV=production webpack --config webpack.config.server.js",
"build": "npm run clean && npm run build:client && npm run build:server",
"build:start": "npm run build && npm run server",
"build:start:perf": "npm run clean && npm run build:client:perf && npm run build:server && npm run server",
"start": "BABEL_ENV=dev babel-node server.js dev",
Expand Down
8 changes: 4 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ if (devServer) {
app.use(webpackHotMiddleware(compiler));
} else {
app.use("/dist", expressStaticGzip("dist"));
app.use(express.static(path.join(__dirname, "dist")));
app.use(express.static(path.resolve(__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"));
res.sendFile(path.resolve(__dirname, "favicon.png"));
});

charon.applyCharonToApp(app);

app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
res.sendFile(path.resolve(__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(global.LOCAL_DATA ? `Data is being sourced from ${global.LOCAL_DATA_PATH}` : "Dataset JSONs are being sourced from S3, narratives via the static github repo");
console.log("-----------------------------------\n\n");
});
2 changes: 1 addition & 1 deletion src/server/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require("path");

const setGlobals = ({localData=false} = {}) => {
global.LOCAL_DATA = localData;
global.LOCAL_DATA_PATH = path.join(__dirname, "..", "..", "/data/");
global.LOCAL_DATA_PATH = path.resolve(__dirname, "..", "..", "data/");
global.REMOTE_DATA_LIVE_BASEURL = "http://data.nextstrain.org/";
global.REMOTE_DATA_STAGING_BASEURL = "http://staging.nextstrain.org/";
global.REMOTE_STATIC_BASEURL = "http://cdn.rawgit.com/nextstrain/static/master/";
Expand Down
4 changes: 2 additions & 2 deletions webpack.config.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module.exports = {
externals: nodeModules,
target: "node",
node: {
__dirname: false,
__filename: false
__dirname: true,
__filename: true
},
output: {
path: path.join(__dirname, ""),
Expand Down