From 975b22a9dc9ddacf8a4bb953119df2381bf43a85 Mon Sep 17 00:00:00 2001 From: Greg Fodor <gfodor@gmail.com> Date: Wed, 18 Apr 2018 19:17:12 -0700 Subject: [PATCH] Set up dev server --- src/hub.js | 5 +++-- src/react-components/hub-create-panel.js | 15 +++++++++++++-- webpack.config.js | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/hub.js b/src/hub.js index cf096150c..cf0f05828 100644 --- a/src/hub.js +++ b/src/hub.js @@ -302,8 +302,9 @@ const onReady = async () => { console.log(`Hub ID: ${hubId}`); const socketProtocol = document.location.protocol === "https:" ? "wss:" : "ws:"; - const socketPort = qs.phx_port || document.location.port; - const socketHost = qs.phx_host || document.location.hostname; + const socketPort = qs.phx_port || (process.env.NODE_ENV === "production" ? document.location.port : 443); + const socketHost = + qs.phx_host || (process.env.NODE_ENV === "production" ? document.location.hostname : "dev.reticulum.io"); const socketUrl = `${socketProtocol}//${socketHost}${socketPort ? `:${socketPort}` : ""}/socket`; console.log(`Phoenix Channel URL: ${socketUrl}`); diff --git a/src/react-components/hub-create-panel.js b/src/react-components/hub-create-panel.js index 32fd19b4e..0caff0292 100644 --- a/src/react-components/hub-create-panel.js +++ b/src/react-components/hub-create-panel.js @@ -38,14 +38,25 @@ class HubCreatePanel extends Component { hub: { name: this.state.name, default_environment_gltf_bundle_url: environment.bundle_url } }; - const res = await fetch("/api/v1/hubs", { + let createUrl = "/api/v1/hubs"; + + if (process.env.NODE_ENV === "development") { + createUrl = `https://dev.reticulum.io${createUrl}`; + } + + const res = await fetch("https://dev.reticulum.io/api/v1/hubs", { body: JSON.stringify(payload), headers: { "content-type": "application/json" }, method: "POST" }); const hub = await res.json(); - document.location = hub.url; + + if (process.env.NODE_ENV === "production") { + document.location = hub.url; + } else { + document.location = `/hub.html?hub_id=${hub.hub_id}`; + } }; isHubNameValid = () => { diff --git a/webpack.config.js b/webpack.config.js index 4f9b26d26..744ae0728 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -87,7 +87,7 @@ const config = { mode: "development", devtool: process.env.NODE_ENV === "production" ? "source-map" : "inline-source-map", devServer: { - open: true, + open: false, https: createHTTPSConfig(), host: "0.0.0.0", useLocalIp: true, -- GitLab