added redirects

This commit is contained in:
Arlo Filley 2024-03-23 00:13:42 +00:00
parent caa177571b
commit 52624bd056
3 changed files with 24 additions and 12 deletions

Binary file not shown.

View File

@ -13,22 +13,26 @@ use crate::cors::CORS;
#[macro_use]
extern crate rocket;
use rocket::{
fs::{relative, FileServer},
response::Redirect,
Build, Rocket
fs::{relative, FileServer},
Build,
Rocket
};
mod api;
mod catchers;
mod redirects;
use crate::api::leaderboard::leaderboard;
use crate::api::sql::Database;
use crate::api::test::{create_test, new_test};
use crate::api::user::{get_tests, login, sign_up};
use catchers::not_found::api_not_found;
use catchers::not_found::frontend_not_found;
use catchers::not_found::documentation_not_found;
use crate::catchers::not_found::api_not_found;
use crate::catchers::not_found::frontend_not_found;
use crate::catchers::not_found::documentation_not_found;
use crate::redirects::leaderboard_redirect;
use crate::redirects::typing_redirect;
// Imports for sql, see sql.rs for more information
@ -39,11 +43,6 @@ fn test() -> &'static str {
"Hello World! I'm A rocket Webserver"
}
#[get("/")]
async fn typing_redirect() -> Redirect {
Redirect::to(uri!("/typing/index.html"))
}
/// The main function which builds and launches the
/// webserver with all appropriate routes and fileservers
#[launch]
@ -69,12 +68,14 @@ async fn rocket() -> Rocket<Build> {
// hosts the fileserver
.mount("/typing", routes![typing_redirect])
.mount("/typing", FileServer::from(relative!("public")))
.register("/typing", catchers![frontend_not_found])
// The state which allows routes to access the database
.manage(Database::new().await.unwrap())
// Redirects
.mount("/typing", routes![typing_redirect])
.mount("/leaderboard", routes![leaderboard_redirect])
// testing only, should return "Hello world"
.mount("/test", routes![test])

11
src/redirects.rs Normal file
View File

@ -0,0 +1,11 @@
use rocket::response::Redirect;
#[get("/")]
pub async fn typing_redirect() -> Redirect {
Redirect::to(uri!("/typing/index.html"))
}
#[get("/")]
pub async fn leaderboard_redirect() -> Redirect {
Redirect::to(uri!("/typing/leaderboard/index.html"))
}