From 27880a5373bbec591893f1418e1fe5dce0d9c165 Mon Sep 17 00:00:00 2001 From: arctic_hen7 Date: Thu, 27 Jan 2022 16:49:58 +1100 Subject: [PATCH] feat: passed reload server info to client --- packages/perseus/src/server/html_shell.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/perseus/src/server/html_shell.rs b/packages/perseus/src/server/html_shell.rs index e0a4ce18dc..a5c34522ba 100644 --- a/packages/perseus/src/server/html_shell.rs +++ b/packages/perseus/src/server/html_shell.rs @@ -88,9 +88,23 @@ impl<'a> HtmlShell<'a> { ); scripts_before_boundary.push(load_wasm_bundle.into()); + // If we're in development, pass through the host/port of the reload server if we're using it + // We'll depend on the `PERSEUS_USE_RELOAD_SERVER` environment variable here, which is set by the CLI's controller process, not the user + // That way, we won't do this if the reload server doesn't exist + #[cfg(debug_assertions)] + if env::var("PERSEUS_USE_RELOAD_SERVER").is_ok() { + let host = + env::var("PERSEUS_RELOAD_SERVER_HOST").unwrap_or_else(|_| "localhost".to_string()); + let port = + env::var("PERSEUS_RELOAD_SERVER_PORT").unwrap_or_else(|_| "8090".to_string()); + scripts_before_boundary + .push(format!("window.__PERSEUS_RELOAD_SERVER_HOST = '{}'", host).into()); + scripts_before_boundary + .push(format!("window.__PERSEUS_RELOAD_SERVER_PORT = '{}'", port).into()); + } + // Add in the `` element at the very top so that it applies to everything in the HTML shell // Otherwise any stylesheets loaded before it won't work properly - // // We add a trailing `/` to the base URL (https://stackoverflow.com/a/26043021) // Note that it's already had any pre-existing ones stripped away let base = format!(r#""#, path_prefix);