Skip to content

Commit

Permalink
server: use JS location.hostname with livereload.js resource
Browse files Browse the repository at this point in the history
Uses JavaScript to dynamically inject the client's hostname.
This allows for serving on 0.0.0.0, where a rendered hostname of
"0.0.0.0" would not resolve necessarily to the server's address.
  • Loading branch information
blueyed committed Jun 27, 2015
1 parent fe61029 commit 2ca26a0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions livereload/server.py
Expand Up @@ -213,9 +213,16 @@ def application(self, port, host, liveport=None, debug=None):
(r'/livereload.js', LiveReloadJSHandler)
]

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

web_handlers = self.get_web_handlers(live_script)

Expand Down

0 comments on commit 2ca26a0

Please sign in to comment.