Skip to content

Commit

Permalink
feat: passed reload server info to client
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Jan 27, 2022
1 parent 1f37700 commit 27880a5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/perseus/src/server/html_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<base>` 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#"<base href="{}/" />"#, path_prefix);
Expand Down

0 comments on commit 27880a5

Please sign in to comment.