Skip to content

Commit

Permalink
Allow for a local production test on local.zooniverse.org
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed May 31, 2024
1 parent db87949 commit 1f23f09
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"start": "export NODE_ENV=development; check-engines && check-dependencies && webpack-dashboard -p 3736 -- webpack-dev-server --config ./webpack.dev.js",
"_build": "export HEAD_COMMIT=$(git rev-parse --short HEAD); check-engines && check-dependencies && rimraf dist; webpack --config ./webpack.build.js --progress --color",
"build-production": "export NODE_ENV=production; npm run _build",
"serve-static": "export NODE_ENV=production; check-engines && check-dependencies && npm run _build && node ./static-server.js",
"serve-static": "npm ci; export NODE_ENV=production; check-engines && check-dependencies && npm run _build && node ./static-server.js",
"test-and-watch": "NODE_ENV=development BABEL_ENV=test mocha --watch --watch-extensions js,jsx,coffee,cjsx test/setup.js test/enzyme-configuration.js $(find app -name *.spec.js*) --reporter nyan || true",
"test": "NODE_ENV=development BABEL_ENV=test nyc mocha --exit test/setup.js test/enzyme-configuration.js $(find app -name *.spec.js*) --reporter nyan || true",
"test-one": "NODE_ENV=development BABEL_ENV=test nyc mocha --exit test/setup.js test/enzyme-configuration.js $1",
Expand Down
17 changes: 11 additions & 6 deletions static-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ const path = require('path');
const app = express();
const port = process.env.PORT || 3735;

const DEVELOPMENT_HOSTS = ['localhost', 'local.zooniverse.org'];

// serve up compiled static assets if we're in production mode
app.use(express.static(__dirname + '/dist'));

app.get('*', function response(req, res) {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});

app.listen(port, 'localhost', function onStart(err) {
if (err) {
console.log(err);
} else {
console.info('==> 🌎 Listening on port %s. Open up http://localhost:%s/ in your browser.', port, port);
}

DEVELOPMENT_HOSTS.forEach((host) => {
app.listen(port, host, function onStart(err) {
if (err) {
console.log(err);
} else {
console.info('==> 🌎 Listening on port %s. Open up http://%s:%s/ in your browser.', port, host, port);
}
});
});

0 comments on commit 1f23f09

Please sign in to comment.