From 1f23f09c7e09b73bffcd408d2414295cd8a5ae5c Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Fri, 31 May 2024 14:43:43 +0100 Subject: [PATCH] Allow for a local production test on local.zooniverse.org --- package.json | 2 +- static-server.js | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 30f1c38d05..3fd81b124e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/static-server.js b/static-server.js index de02162d60..a73e567f0f 100644 --- a/static-server.js +++ b/static-server.js @@ -4,6 +4,8 @@ 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')); @@ -11,10 +13,13 @@ 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); + } + }); });