Skip to content

Commit

Permalink
Updating where reload script is injected to not break document and ke…
Browse files Browse the repository at this point in the history
…eping it from being injected when reload is off
  • Loading branch information
wking-io committed Oct 7, 2019
1 parent 7cc645d commit e9af6ec
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<head>')
res.setHeader('Content-Type', 'text/html')
res.end(`${contents}
<!-- Inserted by elm-live -->
res.end(`
${before}
<head>
${reload ? `
<!-- Inserted by Reload -->
<script src="/reload/reload.js"></script>
<!-- Inserted by elm-live - END -->
<!-- End Reload -->
` : ''}
${after}
`)
}

Expand Down Expand Up @@ -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}`))
Expand Down

0 comments on commit e9af6ec

Please sign in to comment.