diff --git a/server/src/main.rs b/server/src/main.rs index 72c13e9..aeaa4a7 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -68,14 +68,16 @@ async fn main() -> Result<()> { let root_service = service::get(ServeDir::new("static")) .handle_error(|_| Ok::<_, Infallible>(StatusCode::NOT_FOUND)); + const INDEX_PAGE: Html<&'static str> = Html(include_str!("../../dist/index.html")); + axum::Server::bind(&"0.0.0.0:8080".parse()?) .serve( Router::new() - .route("/", post(upload::)) .route( - "/:code", - get(|| async { Html(include_str!("../../dist/index.html")) }), + "/", + post(upload::).get(|| async { INDEX_PAGE }), ) + .route("/:code", get(|| async { INDEX_PAGE })) .nest("/static", root_service) .route( &format!("{}{}", API_ENDPOINT.to_string(), "/:code"), diff --git a/web/src/main.rs b/web/src/main.rs index 113b065..c9d18bb 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -56,6 +56,11 @@ fn open_idb() -> Result { fn main() { std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + if location().pathname().unwrap() == "/" { + render_message("Go away".into()); + return; + } + render_message("Loading paste...".into()); let url = String::from(location().to_string()); @@ -67,9 +72,6 @@ fn main() { Uri::from_parts(uri_parts).unwrap() }; - log!(&url); - log!(&request_uri.to_string()); - log!(&location().pathname().unwrap()); let (key, needs_pw) = { let partial_parsed_url = url .split_once('#') @@ -104,14 +106,13 @@ fn main() { None }; - if location().pathname().unwrap() == "/" { - } else { - spawn_local(async move { - if let Err(e) = fetch_resources(request_uri, key, password).await { - log!(e.to_string()); - } - }); - } + log!(location().pathname().unwrap()); + + spawn_local(async move { + if let Err(e) = fetch_resources(request_uri, key, password).await { + log!(e.to_string()); + } + }); } #[allow(clippy::future_not_send)]