From 17ee4e0058c29f08eec99f6e3d014b1455dc39eb Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Fri, 7 Sep 2018 10:08:01 -0700 Subject: [PATCH] load android ui in dev when browsing to /android (#919) --- android/android.js | 2 +- android/app/src/main/assets/index.html | 14 ++++---------- android/pages/home.js | 5 ----- server/bin/dev.js | 16 ++++++++++++++++ webpack.config.js | 5 +++++ 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/android/android.js b/android/android.js index 7a9ac3f4..39367ef1 100644 --- a/android/android.js +++ b/android/android.js @@ -27,5 +27,5 @@ app.route('/', require('./pages/home').default); app.route('/upload', require('./pages/upload').default); app.route('/share/:id', require('./pages/share').default); app.route('/preferences', require('./pages/preferences').default); -app.route('/android/app/src/main/assets', require('./pages/home').default); +app.route('/android', require('./pages/home').default); app.mount('body'); diff --git a/android/app/src/main/assets/index.html b/android/app/src/main/assets/index.html index ae2d5a2f..404ff156 100644 --- a/android/app/src/main/assets/index.html +++ b/android/app/src/main/assets/index.html @@ -1,17 +1,11 @@ - - + - Firefox Send - - - + + - - \ No newline at end of file + diff --git a/android/pages/home.js b/android/pages/home.js index 93df598e..bc604f6a 100644 --- a/android/pages/home.js +++ b/android/pages/home.js @@ -1,11 +1,6 @@ const html = require('choo/html'); export default function mainPage(state, emit) { - if (window.location.pathname === '/android/app/src/main/assets/') { - // Hack: For debugging the android app in a web browser from - // http://0.0.0.0:8080/android/app/src/main/assets/ after running webpack - state.prefix = '/android/app/src/main/assets'; - } function clickPreferences(event) { event.preventDefault(); emit('pushState', '/preferences'); diff --git a/server/bin/dev.js b/server/bin/dev.js index 7610cb21..ddfbaed2 100644 --- a/server/bin/dev.js +++ b/server/bin/dev.js @@ -1,3 +1,5 @@ +const fs = require('fs'); +const path = require('path'); const assets = require('../../common/assets'); const locales = require('../../common/locales'); const routes = require('../routes'); @@ -8,6 +10,11 @@ const expressWs = require('express-ws'); const morgan = require('morgan'); const config = require('../config'); +const androidIndex = fs.readFileSync( + path.resolve(__dirname, '../../android/app/src/main/assets/index.html'), + 'utf8' +); + module.exports = function(app, devServer) { const wsapp = express(); expressWs(wsapp, null, { perMessageDeflate: false }); @@ -19,6 +26,15 @@ module.exports = function(app, devServer) { app.use(morgan('dev', { stream: process.stderr })); routes(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 // so wait for next tick to add 404 handler process.nextTick(() => app.use(pages.notfound)); diff --git a/webpack.config.js b/webpack.config.js index 0444d08c..754daab2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -183,6 +183,11 @@ const web = { { context: 'public', from: '*.*' + }, + { + context: 'android/app/src/main/assets', + from: '*.*', + to: 'android_asset' } ]), new webpack.IgnorePlugin(/\.\.\/dist/), // used in common/*.js