2018-06-22 20:32:24 +00:00
|
|
|
const assets = require('../../common/assets');
|
|
|
|
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');
|
2019-08-06 21:12:22 +00:00
|
|
|
const expressWs = require('@dannycoates/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
|
|
|
|
2019-03-31 19:42:20 +00:00
|
|
|
const ID_REGEX = '([0-9a-fA-F]{10, 16})';
|
2018-09-10 17:56:59 +00:00
|
|
|
|
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 });
|
2019-05-03 16:25:12 +00:00
|
|
|
routes(wsapp);
|
2018-07-12 20:13:49 +00:00
|
|
|
wsapp.ws('/api/ws', require('../routes/ws'));
|
2020-07-13 17:21:28 +00:00
|
|
|
wsapp.listen(1338, config.listen_address);
|
2018-07-12 20:13:49 +00:00
|
|
|
|
2017-08-24 21:54:02 +00:00
|
|
|
assets.setMiddleware(devServer.middleware);
|
2018-09-04 19:09:03 +00:00
|
|
|
app.use(morgan('dev', { stream: process.stderr }));
|
2018-11-02 22:51:27 +00:00
|
|
|
function android(req, res) {
|
2018-12-13 16:44:28 +00:00
|
|
|
const index = devServer.middleware.fileSystem
|
|
|
|
.readFileSync(devServer.middleware.getFilenameFromUrl('/android.html'))
|
|
|
|
.toString()
|
2019-01-10 20:08:16 +00:00
|
|
|
.replace(
|
|
|
|
'<base href="file:///android_asset/" />',
|
|
|
|
'<base href="http://localhost:8080/" />'
|
|
|
|
);
|
2018-11-02 22:51:27 +00:00
|
|
|
res.set('Content-Type', 'text/html');
|
|
|
|
res.send(index);
|
|
|
|
}
|
2018-09-10 17:56:59 +00: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('/completed', android);
|
|
|
|
app.get('/preferences', android);
|
2018-09-24 20:41:50 +00:00
|
|
|
app.get('/options', android);
|
2018-09-26 19:22:04 +00:00
|
|
|
app.get('/oauth', android);
|
2018-09-10 17:56:59 +00:00
|
|
|
}
|
2017-08-24 21:54:02 +00:00
|
|
|
routes(app);
|
2018-02-21 04:31:27 +00:00
|
|
|
tests(app);
|
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));
|
|
|
|
};
|