Skip to content

Commit c157e4d

Browse files
committed
created server/bin/ for server entrypoints
- added server/bin/test.js for the frontend test runner
1 parent dafe488 commit c157e4d

File tree

7 files changed

+35
-17
lines changed

7 files changed

+35
-17
lines changed

docs/build.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ Send has two build configurations, development and production. Both can be run v
22

33
# Development
44

5-
`npm start` launches a `webpack-dev-server` on port 8080 that compiles the assets and watches files for changes. It also serves the backend API and frontend unit tests via the `server/dev.js` entrypoint. The frontend tests can be run in the browser by navigating to http://localhost:8080/test and will rerun automatically as the watched files are saved with changes.
5+
`npm start` launches a `webpack-dev-server` on port 8080 that compiles the assets and watches files for changes. It also serves the backend API and frontend unit tests via the `server/bin/dev.js` entrypoint. The frontend tests can be run in the browser by navigating to http://localhost:8080/test and will rerun automatically as the watched files are saved with changes.
66

77
# Production
88

9-
`npm run build` compiles the assets and writes the files to the `dist/` directory. `npm run prod` launches an Express server on port 1443 that serves the backend API and frontend static assets from `dist/` via the `server/prod.js` entrypoint.
9+
`npm run build` compiles the assets and writes the files to the `dist/` directory. `npm run prod` launches an Express server on port 1443 that serves the backend API and frontend static assets from `dist/` via the `server/bin/prod.js` entrypoint.
1010

1111
# Notable differences
1212

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"test-integration": "docker-compose up --abort-on-container-exit --exit-code-from integration-tests --build --remove-orphans --quiet-pull && docker-compose down",
3232
"test-integration-stage": "cross-env BASE_URL=https://send.stage.mozaws.net npm run test-integration",
3333
"start": "npm run clean && cross-env NODE_ENV=development webpack-dev-server",
34-
"prod": "node server/prod.js"
34+
"prod": "node server/bin/prod.js"
3535
},
3636
"lint-staged": {
3737
"*.js": [

server/dev.js renamed to server/bin/dev.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const assets = require('../common/assets');
2-
const locales = require('../common/locales');
3-
const routes = require('./routes');
4-
const pages = require('./routes/pages');
5-
const tests = require('../test/frontend/routes');
1+
const assets = require('../../common/assets');
2+
const locales = require('../../common/locales');
3+
const routes = require('../routes');
4+
const pages = require('../routes/pages');
5+
const tests = require('../../test/frontend/routes');
66
const express = require('express');
77
const expressWs = require('express-ws');
8-
const config = require('./config');
8+
const config = require('../config');
99

1010
const wsapp = express();
1111
expressWs(wsapp, null, { perMessageDeflate: false });
12-
wsapp.ws('/api/ws', require('./routes/ws'));
12+
wsapp.ws('/api/ws', require('../routes/ws'));
1313
wsapp.listen(8081, config.listen_address);
1414

1515
module.exports = function(app, devServer) {

server/prod.js renamed to server/bin/prod.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const express = require('express');
22
const path = require('path');
33
const Raven = require('raven');
4-
const config = require('./config');
5-
const routes = require('./routes');
6-
const pages = require('./routes/pages');
4+
const config = require('../config');
5+
const routes = require('../routes');
6+
const pages = require('../routes/pages');
77
const expressWs = require('express-ws');
88

99
if (config.sentry_dsn) {
@@ -12,11 +12,11 @@ if (config.sentry_dsn) {
1212

1313
const app = express();
1414
expressWs(app, null, { perMessageDeflate: false });
15-
app.ws('/api/ws', require('./routes/ws'));
15+
app.ws('/api/ws', require('../routes/ws'));
1616
routes(app);
1717

1818
app.use(
19-
express.static(path.resolve(__dirname, '../dist/'), {
19+
express.static(path.resolve(__dirname, '../../dist/'), {
2020
setHeaders: function(res) {
2121
res.set('Cache-Control', 'public, max-age=31536000, immutable');
2222
res.removeHeader('Pragma');

server/bin/test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const assets = require('../../common/assets');
2+
const locales = require('../../common/locales');
3+
const routes = require('../routes');
4+
const pages = require('../routes/pages');
5+
const tests = require('../../test/frontend/routes');
6+
const expressWs = require('express-ws');
7+
8+
module.exports = function(app, devServer) {
9+
assets.setMiddleware(devServer.middleware);
10+
locales.setMiddleware(devServer.middleware);
11+
expressWs(app, null, { perMessageDeflate: false });
12+
app.ws('/api/ws', require('../routes/ws'));
13+
routes(app);
14+
tests(app);
15+
// webpack-dev-server routes haven't been added yet
16+
// so wait for next tick to add 404 handler
17+
process.nextTick(() => app.use(pages.notfound));
18+
};

test/frontend/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const webpack = require('webpack');
77
const config = require('../../webpack.config');
88
const middleware = require('webpack-dev-middleware');
99
const express = require('express');
10-
const devRoutes = require('../../server/dev');
10+
const devRoutes = require('../../server/bin/test');
1111
const app = express();
1212

1313
const wpm = middleware(webpack(config), { logLevel: 'silent' });

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ module.exports = {
209209
devServer: {
210210
compress: true,
211211
host: '0.0.0.0',
212-
before: IS_DEV ? require('./server/dev') : undefined,
212+
before: IS_DEV ? require('./server/bin/dev') : undefined,
213213
proxy: {
214214
'/api/ws': {
215215
target: 'ws://localhost:8081',

0 commit comments

Comments
 (0)