2018-06-22 22:32:24 +02: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 02:05:33 +02:00
|
|
|
const express = require('express');
|
|
|
|
const expressWs = require('express-ws');
|
2018-09-04 21:09:03 +02:00
|
|
|
const morgan = require('morgan');
|
2018-06-22 22:32:24 +02:00
|
|
|
const config = require('../config');
|
2018-06-21 02:05:33 +02:00
|
|
|
|
2018-09-10 19:56:59 +02:00
|
|
|
const ID_REGEX = '([0-9a-fA-F]{10})';
|
|
|
|
|
2017-08-24 23:54:02 +02:00
|
|
|
module.exports = function(app, devServer) {
|
2018-07-12 22:13:49 +02: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 23:54:02 +02:00
|
|
|
assets.setMiddleware(devServer.middleware);
|
|
|
|
locales.setMiddleware(devServer.middleware);
|
2018-09-04 21:09:03 +02:00
|
|
|
app.use(morgan('dev', { stream: process.stderr }));
|
2018-11-02 23:51:27 +01:00
|
|
|
function android(req, res) {
|
|
|
|
const index = devServer.middleware.fileSystem.readFileSync(
|
2018-11-06 20:21:14 +01:00
|
|
|
devServer.middleware.getFilenameFromUrl('/android.html')
|
2018-11-02 23:51:27 +01:00
|
|
|
);
|
|
|
|
res.set('Content-Type', 'text/html');
|
|
|
|
res.send(index);
|
|
|
|
}
|
2018-09-10 19:56:59 +02:00
|
|
|
if (process.env.ANDROID) {
|
|
|
|
// map all html routes to the android index.html
|
|
|
|
app.get('/', android);
|
|
|
|
app.get('/legal', android);
|
|
|
|
app.get(`/share/:id${ID_REGEX}`, android);
|
|
|
|
app.get(`/download/:id${ID_REGEX}`, android);
|
|
|
|
app.get('/completed', android);
|
|
|
|
app.get('/preferences', android);
|
2018-09-24 22:41:50 +02:00
|
|
|
app.get('/options', android);
|
2018-09-26 21:22:04 +02:00
|
|
|
app.get('/oauth', android);
|
2018-09-10 19:56:59 +02:00
|
|
|
}
|
2017-08-24 23:54:02 +02:00
|
|
|
routes(app);
|
2018-02-21 05:31:27 +01:00
|
|
|
tests(app);
|
2017-08-24 23:54:02 +02: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));
|
|
|
|
};
|