Просмотр исходного кода

created server/bin/ for server entrypoints

- added server/bin/test.js for the frontend test runner
Danny Coates 6 лет назад
Родитель
Сommit
c157e4d31c
7 измененных файлов с 35 добавлено и 17 удалено
  1. 2 2
      docs/build.md
  2. 1 1
      package.json
  3. 7 7
      server/bin/dev.js
  4. 5 5
      server/bin/prod.js
  5. 18 0
      server/bin/test.js
  6. 1 1
      test/frontend/runner.js
  7. 1 1
      webpack.config.js

+ 2 - 2
docs/build.md

@@ -2,11 +2,11 @@ Send has two build configurations, development and production. Both can be run v
 
 # Development
 
-`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.
+`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.
 
 # Production
 
-`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.
+`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.
 
 # Notable differences
 

+ 1 - 1
package.json

@@ -31,7 +31,7 @@
     "test-integration": "docker-compose up --abort-on-container-exit --exit-code-from integration-tests --build --remove-orphans --quiet-pull && docker-compose down",
     "test-integration-stage": "cross-env BASE_URL=https://send.stage.mozaws.net npm run test-integration",
     "start": "npm run clean && cross-env NODE_ENV=development webpack-dev-server",
-    "prod": "node server/prod.js"
+    "prod": "node server/bin/prod.js"
   },
   "lint-staged": {
     "*.js": [

+ 7 - 7
server/dev.js → server/bin/dev.js

@@ -1,15 +1,15 @@
-const assets = require('../common/assets');
-const locales = require('../common/locales');
-const routes = require('./routes');
-const pages = require('./routes/pages');
-const tests = require('../test/frontend/routes');
+const assets = require('../../common/assets');
+const locales = require('../../common/locales');
+const routes = require('../routes');
+const pages = require('../routes/pages');
+const tests = require('../../test/frontend/routes');
 const express = require('express');
 const expressWs = require('express-ws');
-const config = require('./config');
+const config = require('../config');
 
 const wsapp = express();
 expressWs(wsapp, null, { perMessageDeflate: false });
-wsapp.ws('/api/ws', require('./routes/ws'));
+wsapp.ws('/api/ws', require('../routes/ws'));
 wsapp.listen(8081, config.listen_address);
 
 module.exports = function(app, devServer) {

+ 5 - 5
server/prod.js → server/bin/prod.js

@@ -1,9 +1,9 @@
 const express = require('express');
 const path = require('path');
 const Raven = require('raven');
-const config = require('./config');
-const routes = require('./routes');
-const pages = require('./routes/pages');
+const config = require('../config');
+const routes = require('../routes');
+const pages = require('../routes/pages');
 const expressWs = require('express-ws');
 
 if (config.sentry_dsn) {
@@ -12,11 +12,11 @@ if (config.sentry_dsn) {
 
 const app = express();
 expressWs(app, null, { perMessageDeflate: false });
-app.ws('/api/ws', require('./routes/ws'));
+app.ws('/api/ws', require('../routes/ws'));
 routes(app);
 
 app.use(
-  express.static(path.resolve(__dirname, '../dist/'), {
+  express.static(path.resolve(__dirname, '../../dist/'), {
     setHeaders: function(res) {
       res.set('Cache-Control', 'public, max-age=31536000, immutable');
       res.removeHeader('Pragma');

+ 18 - 0
server/bin/test.js

@@ -0,0 +1,18 @@
+const assets = require('../../common/assets');
+const locales = require('../../common/locales');
+const routes = require('../routes');
+const pages = require('../routes/pages');
+const tests = require('../../test/frontend/routes');
+const expressWs = require('express-ws');
+
+module.exports = function(app, devServer) {
+  assets.setMiddleware(devServer.middleware);
+  locales.setMiddleware(devServer.middleware);
+  expressWs(app, null, { perMessageDeflate: false });
+  app.ws('/api/ws', require('../routes/ws'));
+  routes(app);
+  tests(app);
+  // webpack-dev-server routes haven't been added yet
+  // so wait for next tick to add 404 handler
+  process.nextTick(() => app.use(pages.notfound));
+};

+ 1 - 1
test/frontend/runner.js

@@ -7,7 +7,7 @@ const webpack = require('webpack');
 const config = require('../../webpack.config');
 const middleware = require('webpack-dev-middleware');
 const express = require('express');
-const devRoutes = require('../../server/dev');
+const devRoutes = require('../../server/bin/test');
 const app = express();
 
 const wpm = middleware(webpack(config), { logLevel: 'silent' });

+ 1 - 1
webpack.config.js

@@ -209,7 +209,7 @@ module.exports = {
   devServer: {
     compress: true,
     host: '0.0.0.0',
-    before: IS_DEV ? require('./server/dev') : undefined,
+    before: IS_DEV ? require('./server/bin/dev') : undefined,
     proxy: {
       '/api/ws': {
         target: 'ws://localhost:8081',