Skip to content

Commit

Permalink
Update to use production server and local data
Browse files Browse the repository at this point in the history
  • Loading branch information
trvrb committed Nov 30, 2016
1 parent acef132 commit 17fbe1a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 56 deletions.
57 changes: 8 additions & 49 deletions dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,26 @@ var webpack = require("webpack");
var config = require("./webpack.config.dev");
var request = require("request");

var Zika_meta = require("./data/zika_meta.json");
var Zika_tree = require("./data/zika_tree.json");
var Zika_entropy = require("./data/zika_entropy.json");
var Zika_sequences = require("./data/zika_sequences.json");

var app = express();
var compiler = webpack(config);

app.set('port', 4000);

app.use('/data', express.static('data'))

app.use(require("webpack-dev-middleware")(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));

app.use(require("webpack-hot-middleware")(compiler));

app.get("/meta", function(req, res) {
res.send(Zika_meta);
});

app.get("/tree", function(req, res) {
res.send(Zika_tree);
});

app.get("/sequences", function(req, res) {
res.send(Zika_entropy);
});

app.get("/frequencies", function(req, res) {
res.send({});
});

app.get("/entropy", function(req, res) {
res.send(Zika_entropy);
});


// app.get("/:virus/:strain/:timeperiod/:resource", function(req, res) {
// request(
// "http://nextstrain.org/data/" +
// req.params.virus +
// req.params.strain +
// req.params.timeperiod || "" +
// req.params.resource +
// ".json",
// (err,r) => {
// if (err) {console.log('error getting data', err)}
// res.send(r.toJSON());
// });
// });

app.get("*", function(req, res) {
res.sendFile(path.join(__dirname, "index.html"));
});

var port = 4000;

app.listen(port, "localhost", function(err) {
if (err) {
console.log("error", err);
return;
}

console.log("Listening at http://localhost:" + port);
// Listen for requests
var server = app.listen(app.get('port'), function() {
var port = server.address().port;
console.log('Listening on port ' + port);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build:webpack": "NODE_ENV=production webpack --config webpack.config.js",
"build": "npm run clean && npm run build:webpack",
"start": "node dev-server.js",
"fetchAndStart": "sh fetch_data.sh && node dev-server.js",
"fetchAndStart": "sh fetch_data.sh && node server.js",
"lint": "eslint src"
},
"author": "Trevor Bedford and Richard Neher",
Expand Down
17 changes: 17 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var path = require("path");
var express = require("express");

var app = express();
app.set('port', 4000);
app.use('/data', express.static('data'))
app.use('/dist', express.static('dist'))

app.get("*", function(req, res) {
res.sendFile(path.join(__dirname, "index.html"));
});

// Listen for requests
var server = app.listen(app.get('port'), function() {
var port = server.address().port;
console.log('Listening on port ' + port);
});
23 changes: 18 additions & 5 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ const fetchMetadata = (q) => {
this will resolve to something like:
/data/flu_h3n2_3y_meta.json
*/
return fetch("/meta");
return fetch(
"/data/" +
q + "_meta.json"
);
};

export const populateMetadataStore = (queryParams) => {
Expand Down Expand Up @@ -77,7 +80,10 @@ const treeFetchError = (err) => {
};

const fetchTree = (q) => {
return fetch("/tree");
return fetch(
"/data/" +
q + "_tree.json"
);
};

export const populateTreeStore = (queryParams) => {
Expand Down Expand Up @@ -113,7 +119,10 @@ const sequencesFetchError = (err) => {
};

const fetchSequences = (q) => {
return fetch("/sequences");
return fetch(
"/data/" +
q + "_sequences.json"
);
};

export const populateSequencesStore = (queryParams) => {
Expand Down Expand Up @@ -148,7 +157,10 @@ const frequenciesFetchError = (err) => {
};

const fetchFrequencies = (q) => {
return fetch("/frequencies");
return fetch(
"/data/" +
q + "_frequencies.json"
);
};

export const populateFrequenciesStore = (queryParams) => {
Expand Down Expand Up @@ -183,7 +195,8 @@ const entropyFetchError = (err) => {
};

const fetchEntropy = (q) => {
return fetch("/entropy");
return fetch("/data/" +
q + "_entropy.json");
};

export const populateEntropyStore = (queryParams) => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const datasets={
},
'zika':{},
'ebola':{},
'default':'flu'
'default':'zika'
}
}

Expand Down

0 comments on commit 17fbe1a

Please sign in to comment.