"Support" index page fetch
This commit is contained in:
parent
05d736e88e
commit
4f5d1c46d3
2 changed files with 17 additions and 14 deletions
|
@ -68,14 +68,16 @@ async fn main() -> Result<()> {
|
||||||
let root_service = service::get(ServeDir::new("static"))
|
let root_service = service::get(ServeDir::new("static"))
|
||||||
.handle_error(|_| Ok::<_, Infallible>(StatusCode::NOT_FOUND));
|
.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()?)
|
axum::Server::bind(&"0.0.0.0:8080".parse()?)
|
||||||
.serve(
|
.serve(
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/", post(upload::<SHORT_CODE_SIZE>))
|
|
||||||
.route(
|
.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)
|
.nest("/static", root_service)
|
||||||
.route(
|
.route(
|
||||||
&format!("{}{}", API_ENDPOINT.to_string(), "/:code"),
|
&format!("{}{}", API_ENDPOINT.to_string(), "/:code"),
|
||||||
|
|
|
@ -56,6 +56,11 @@ fn open_idb() -> Result<IdbOpenDbRequest> {
|
||||||
fn main() {
|
fn main() {
|
||||||
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
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());
|
render_message("Loading paste...".into());
|
||||||
|
|
||||||
let url = String::from(location().to_string());
|
let url = String::from(location().to_string());
|
||||||
|
@ -67,9 +72,6 @@ fn main() {
|
||||||
Uri::from_parts(uri_parts).unwrap()
|
Uri::from_parts(uri_parts).unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
log!(&url);
|
|
||||||
log!(&request_uri.to_string());
|
|
||||||
log!(&location().pathname().unwrap());
|
|
||||||
let (key, needs_pw) = {
|
let (key, needs_pw) = {
|
||||||
let partial_parsed_url = url
|
let partial_parsed_url = url
|
||||||
.split_once('#')
|
.split_once('#')
|
||||||
|
@ -104,14 +106,13 @@ fn main() {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
if location().pathname().unwrap() == "/" {
|
log!(location().pathname().unwrap());
|
||||||
} else {
|
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
if let Err(e) = fetch_resources(request_uri, key, password).await {
|
if let Err(e) = fetch_resources(request_uri, key, password).await {
|
||||||
log!(e.to_string());
|
log!(e.to_string());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::future_not_send)]
|
#[allow(clippy::future_not_send)]
|
||||||
|
|
Loading…
Reference in a new issue