added ANDROID environment variable to dev server for hosting the android html

This commit is contained in:
Danny Coates 2018-09-10 10:56:59 -07:00
parent a8b305a84e
commit 20528eb0d1
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
2 changed files with 22 additions and 10 deletions

View File

@ -27,5 +27,4 @@ app.route('/', require('./pages/home').default);
app.route('/upload', require('./pages/upload').default); app.route('/upload', require('./pages/upload').default);
app.route('/share/:id', require('./pages/share').default); app.route('/share/:id', require('./pages/share').default);
app.route('/preferences', require('./pages/preferences').default); app.route('/preferences', require('./pages/preferences').default);
app.route('/android', require('./pages/home').default);
app.mount('body'); app.mount('body');

View File

@ -10,11 +10,23 @@ const expressWs = require('express-ws');
const morgan = require('morgan'); const morgan = require('morgan');
const config = require('../config'); const config = require('../config');
const ID_REGEX = '([0-9a-fA-F]{10})';
const androidIndex = fs.readFileSync( const androidIndex = fs.readFileSync(
path.resolve(__dirname, '../../android/app/src/main/assets/index.html'), path.resolve(__dirname, '../../android/app/src/main/assets/index.html'),
'utf8' 'utf8'
); );
function android(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'))
);
}
module.exports = function(app, devServer) { module.exports = function(app, devServer) {
const wsapp = express(); const wsapp = express();
expressWs(wsapp, null, { perMessageDeflate: false }); expressWs(wsapp, null, { perMessageDeflate: false });
@ -24,17 +36,18 @@ module.exports = function(app, devServer) {
assets.setMiddleware(devServer.middleware); assets.setMiddleware(devServer.middleware);
locales.setMiddleware(devServer.middleware); locales.setMiddleware(devServer.middleware);
app.use(morgan('dev', { stream: process.stderr })); app.use(morgan('dev', { stream: process.stderr }));
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);
app.get('/api/fxa/oauth', android);
}
routes(app); routes(app);
tests(app); tests(app);
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'))
);
});
// webpack-dev-server routes haven't been added yet // webpack-dev-server routes haven't been added yet
// so wait for next tick to add 404 handler // so wait for next tick to add 404 handler
process.nextTick(() => app.use(pages.notfound)); process.nextTick(() => app.use(pages.notfound));