Add home page
This commit is contained in:
parent
23167ae077
commit
4fadbc2d4b
12
src/main.rs
12
src/main.rs
|
@ -31,11 +31,21 @@ async fn async_main(port: u16) {
|
|||
.and(client.clone())
|
||||
.and_then(handle_album);
|
||||
let media_path = warp::path!(String).and(client).and_then(handle_media);
|
||||
let root_handler = warp::path::end().map(|| warp::reply::html(
|
||||
format!("<html><head><style>body {{ background-color: black; color: black; text-align: center; }}\ndiv {{ border: 1px solid #008; background: #eef; padding: 0.5em 1em 0.5em 1em; }}</style></head><body><div><b><a href=\"https://gitlab.com/blankX/imgurx\" style=\"text-decoration: none;\">ImgurX v{}</a></b><br>An alternative JS-less Imgur frontend</div></body></html>", env!("CARGO_PKG_VERSION"))
|
||||
));
|
||||
let index_handler = warp::path("index.html").and(root_handler);
|
||||
let not_found_handler = warp::any().map(|| warp::reply::with_status(
|
||||
warp::reply::html("<html><head><style>body { background-color: black; color: white; text-align: center; }\ndiv { border: 1px solid #fcc; background: #fee; padding: 0.5em 1em 0.5em 1em; color: black; }</style></head><body><div><b>404: Not Found</b></div></body></html>"),
|
||||
404.try_into().unwrap(),
|
||||
));
|
||||
let routes = warp::filters::method::get().and(album_path.or(media_path).or(not_found_handler));
|
||||
let routes = warp::filters::method::get().and(
|
||||
album_path
|
||||
.or(index_handler)
|
||||
.or(media_path)
|
||||
.or(root_handler)
|
||||
.or(not_found_handler),
|
||||
);
|
||||
eprintln!("Serving on 0.0.0.0:{}", port);
|
||||
warp::serve(routes).run(([0u8, 0, 0, 0], port)).await;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue