added redirects
This commit is contained in:
parent
caa177571b
commit
52624bd056
Binary file not shown.
23
src/main.rs
23
src/main.rs
@ -14,21 +14,25 @@ use crate::cors::CORS;
|
||||
extern crate rocket;
|
||||
use rocket::{
|
||||
fs::{relative, FileServer},
|
||||
response::Redirect,
|
||||
Build, Rocket
|
||||
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
11
src/redirects.rs
Normal 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"))
|
||||
}
|
Loading…
Reference in New Issue
Block a user