diff --git a/src/app.ts b/src/app.ts index 3009616..1a26b5d 100644 --- a/src/app.ts +++ b/src/app.ts @@ -10,7 +10,6 @@ import indexRouter from './routes'; import {HttpLogger, Redis, Config, setupAuthProxy, getReloadRouter, polyfillRoute} from './utils'; import {Store} from 'express-session'; - export const app = express(); // view engine setup @@ -29,7 +28,7 @@ app.use(express.json()); app.use(express.urlencoded({extended: false})); // compression -app.use(compression); +app.use(compression()); // auth proxy middleware router.use(setupAuthProxy); diff --git a/src/utils/auto-reload.ts b/src/utils/auto-reload.ts index 4ea331b..ff6375a 100644 --- a/src/utils/auto-reload.ts +++ b/src/utils/auto-reload.ts @@ -26,18 +26,24 @@ export function getReloadRouter(): Router { res.send(` const loc = window.location; const url = loc.protocol+'//'+loc.host+'${urlJoin(req.baseUrl, "/auto-reload")}'; - const parse = async res => (await res.json()).uuid; + // const parse = async res => (await res.json()).uuid; + const parse = function(res) { + return res.json() + .then(function(json) {return json.uuid;}) } let hash = undefined; let hadError = false; - setInterval(async () => { + setInterval(function() { try { - const data = await parse(await fetch(url)); - if (data) { - hash = hash === undefined ? data : hash; - if (hash !== data) { - window.location.reload(); - } - } + fetch(url) + .then(function(res) { return parse(res) }) + .then(function(data) { + if (data) { + hash = hash === undefined ? data : hash; + if (hash !== data) { + window.location.reload(); + } + } + }); } catch (e) { if (hadError === false) { console.log(e); diff --git a/src/utils/polyfill.ts b/src/utils/polyfill.ts index 709eef7..22894aa 100644 --- a/src/utils/polyfill.ts +++ b/src/utils/polyfill.ts @@ -16,6 +16,7 @@ const features = new WaitForSync(); return feats; })() .then(feats => { + feats["fetch"] = {}; Logger.debug("Polyfill analysed:", Object.keys(feats)); features.setData(feats); }) diff --git a/views/layout.pug b/views/layout.pug index 9ce1da7..0f8efd8 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -4,8 +4,6 @@ html head title= title link(rel='stylesheet', href=baseUrl+'/styles/style.css') - if !Config.isProduction - script(type='text/javascript', async, src=baseUrl+'/auto-reload/client.js') body block content script(type='text/javascript', src=baseUrl+'/js/polyfill.js') @@ -15,3 +13,5 @@ html require(['src/index'], function (index) { index.setConfig({EXTERNAL_BASE_URL: '#{baseUrl}'}); }); + if !Config.isProduction + script(type='text/javascript', src=baseUrl+'/auto-reload/client.js')