"Support" index page fetch

This commit is contained in:
Edward Shen 2021-10-31 01:16:31 -07:00
parent 05d736e88e
commit 4f5d1c46d3
Signed by: edward
GPG key ID: 19182661E818369F
2 changed files with 17 additions and 14 deletions

View file

@ -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::<SHORT_CODE_SIZE>))
.route(
"/:code",
get(|| async { Html(include_str!("../../dist/index.html")) }),
"/",
post(upload::<SHORT_CODE_SIZE>).get(|| async { INDEX_PAGE }),
)
.route("/:code", get(|| async { INDEX_PAGE }))
.nest("/static", root_service)
.route(
&format!("{}{}", API_ENDPOINT.to_string(), "/:code"),

View file

@ -56,6 +56,11 @@ fn open_idb() -> Result<IdbOpenDbRequest> {
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 {
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)]