2018-09-07 17:08:01 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2018-06-22 20:32:24 +00:00
|
|
|
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');
|
2018-06-21 00:05:33 +00:00
|
|
|
const express = require('express');
|
|
|
|
const expressWs = require('express-ws');
|
2018-09-04 19:09:03 +00:00
|
|
|
const morgan = require('morgan');
|
2018-06-22 20:32:24 +00:00
|
|
|
const config = require('../config');
|
2018-06-21 00:05:33 +00:00
|
|
|
|
2018-09-07 17:08:01 +00:00
|
|
|
const androidIndex = fs.readFileSync(
|
|
|
|
path.resolve(__dirname, '../../android/app/src/main/assets/index.html'),
|
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
2017-08-24 21:54:02 +00:00
|
|
|
module.exports = function(app, devServer) {
|
2018-07-12 20:13:49 +00:00
|
|
|
const wsapp = express();
|
|
|
|
expressWs(wsapp, null, { perMessageDeflate: false });
|
|
|
|
wsapp.ws('/api/ws', require('../routes/ws'));
|
|
|
|
wsapp.listen(8081, config.listen_address);
|
|
|
|
|
2017-08-24 21:54:02 +00:00
|
|
|
assets.setMiddleware(devServer.middleware);
|
|
|
|
locales.setMiddleware(devServer.middleware);
|
2018-09-04 19:09:03 +00:00
|
|
|
app.use(morgan('dev', { stream: process.stderr }));
|
2017-08-24 21:54:02 +00:00
|
|
|
routes(app);
|
2018-02-21 04:31:27 +00:00
|
|
|
tests(app);
|
2018-09-07 17:08:01 +00:00
|
|
|
app.get('/android', function(req, res) {
|
|
|
|
res.set('Content-Type', 'text/html');
|
|
|
|
res.send(
|
|
|
|
androidIndex
|
|
|
|
.replace('index.css', '/android_asset/index.css')
|
|
|
|
.replace('vendor.js', assets.get('vendor.js'))
|
|
|
|
.replace('android.js', assets.get('android.js'))
|
|
|
|
);
|
|
|
|
});
|
2017-08-24 21:54:02 +00:00
|
|
|
// webpack-dev-server routes haven't been added yet
|
|
|
|
// so wait for next tick to add 404 handler
|
|
|
|
process.nextTick(() => app.use(pages.notfound));
|
|
|
|
};
|