1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-10 05:02:45 +01:00

created server/bin/ for server entrypoints

- added server/bin/test.js for the frontend test runner
This commit is contained in:
Danny Coates 2018-06-22 13:32:24 -07:00
parent dafe4884fc
commit c157e4d31c
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
7 changed files with 35 additions and 17 deletions

View File

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

View File

@ -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": "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", "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", "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": { "lint-staged": {
"*.js": [ "*.js": [

View File

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

View File

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

18
server/bin/test.js Normal file
View File

@ -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));
};

View File

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

View File

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