From e9af6ecee3a8b1ea9261927a1e6c7377505aab3f Mon Sep 17 00:00:00 2001 From: Will King Date: Mon, 7 Oct 2019 10:43:54 -0500 Subject: [PATCH] Updating where reload script is injected to not break document and keeping it from being injected when reload is off --- lib/src/start.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/src/start.js b/lib/src/start.js index b3885d2..b727e4c 100644 --- a/lib/src/start.js +++ b/lib/src/start.js @@ -123,13 +123,18 @@ function parseUrl (pathname, model) { * * This function resolves the request with the passed in contents and includes the reload script. **/ -const resolveWith = res => contents => { +const resolveWith = (reload, res) => contents => { + const [before, after] = contents.split('') res.setHeader('Content-Type', 'text/html') - res.end(`${contents} - - + res.end(` +${before} + +${reload ? ` + - + +` : ''} +${after} `) } @@ -184,7 +189,7 @@ function handler (model) { } else if (url.isType(CONTENT_TYPE)) { readFile(url.getPath, 'utf8') .alt(readFile(url.rootpath, 'utf8')) - .fork(resolveNotFound(res), resolveWith(res)) + .fork(resolveNotFound(res), resolveWith(model.reload, res)) } else if (url.isType(RELOAD_TYPE)) { readFile(RELOAD_FILE, 'utf8') .map(file => file.replace(`'{{verbose}}'`, `${model.verbose}`))