Skip to content

Commit b187d80

Browse files
committed
Merge pull request #116 from blueyed/livereload-snippet-via-js
server: use JS location.hostname with livereload.js resource
2 parents fe61029 + 2ca26a0 commit b187d80

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

livereload/server.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,16 @@ def application(self, port, host, liveport=None, debug=None):
213213
(r'/livereload.js', LiveReloadJSHandler)
214214
]
215215

216+
# The livereload.js snippet.
217+
# Uses JavaScript to dynamically inject the client's hostname.
218+
# This allows for serving on 0.0.0.0.
216219
live_script = escape.utf8((
217-
'<script src="http://{host}:{port}/livereload.js"></script>'
218-
).format(host=host, port=liveport))
220+
'<script type="text/javascript">'
221+
'document.write("<script src=''http://"'
222+
' + window.location.hostname + ":{port}/livereload.js''>'
223+
' </"+"script>");'
224+
'</script>'
225+
).format(port=liveport))
219226

220227
web_handlers = self.get_web_handlers(live_script)
221228

0 commit comments

Comments
 (0)