Commit 1dbbd4a9 authored by Robert Knight's avatar Robert Knight

Make client test page load embed from same hostname as test page

Previously the live reload server at http://localhost:3000 hardcoded the
embed script to 'http://localhost:5000' which would cause the embed to
fail to load if accessing the live reload server via a different IP.

This happens when accessing the server through a VirtualBox Guest when
using the default networking settings or when accessing it from a say, a
mobile device on the same WiFi network as a laptop serving the dev
environment.

Instead use the same hostname for the live reload WebSocket server
and embed script as the client test page is served from.
parent 5534de80
...@@ -38,9 +38,11 @@ function LiveReloadServer(port, appServer) { ...@@ -38,9 +38,11 @@ function LiveReloadServer(port, appServer) {
<body> <body>
<pre style="margin: 75px;">${changelogText()}</pre> <pre style="margin: 75px;">${changelogText()}</pre>
<script> <script>
var appHost = document.location.hostname;
window.hypothesisConfig = function () { window.hypothesisConfig = function () {
return { return {
liveReloadServer: 'ws://localhost:${port}', liveReloadServer: 'ws://' + appHost + ':${port}',
// Open the sidebar when the page loads // Open the sidebar when the page loads
firstRun: true, firstRun: true,
...@@ -52,8 +54,11 @@ function LiveReloadServer(port, appServer) { ...@@ -52,8 +54,11 @@ function LiveReloadServer(port, appServer) {
window.location.reload(); window.location.reload();
} }
}); });
var embedScript = document.createElement('script');
embedScript.src = '${appServer}/embed.js'.replace('localhost', appHost);
document.body.appendChild(embedScript);
</script> </script>
<script src="${appServer}/embed.js"></script>
</body> </body>
</html> </html>
`; `;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment