-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a653ffe
commit e2ce4bc
Showing
39 changed files
with
141 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/server/controller/challenge.rs → src/web/controller/challenge.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
src/server/controller/submission.rs → src/web/controller/submission.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::{fs, path::PathBuf}; | ||
|
||
use axum::{ | ||
extract::Request, | ||
http::{Response, StatusCode}, | ||
middleware::Next, | ||
response::IntoResponse, | ||
}; | ||
|
||
pub async fn serve(req: Request, next: Next) -> Result<axum::response::Response, StatusCode> { | ||
let path: String = req.uri().path().to_string(); | ||
|
||
if path.starts_with("/api") { | ||
return Ok(next.run(req).await); | ||
} | ||
|
||
let filepath = PathBuf::from("dist").join(path.strip_prefix("/").unwrap_or_default()); | ||
|
||
async fn index() -> Result<axum::response::Response, StatusCode> { | ||
if let Ok(index_content) = fs::read_to_string(PathBuf::from("dist").join("index.html")) { | ||
return Ok(Response::builder().status(StatusCode::OK).body(index_content).unwrap().into_response()); | ||
} else { | ||
return Ok(Response::builder() | ||
.status(StatusCode::NOT_FOUND) | ||
.body("404 Not Found".to_string()) | ||
.unwrap() | ||
.into_response()); | ||
} | ||
} | ||
|
||
if filepath == PathBuf::from("dist").join("index.html") { | ||
return index().await; | ||
} | ||
|
||
if let Ok(content) = fs::read_to_string(&filepath) { | ||
return Ok(Response::builder().status(StatusCode::OK).body(content).unwrap().into_response()); | ||
} else { | ||
return index().await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod auth; | ||
pub mod frontend; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
pub mod controller; | ||
pub mod middleware; | ||
pub mod router; | ||
pub mod service; | ||
|
||
use std::sync::OnceLock; | ||
|
||
use axum::{middleware::from_fn, Router}; | ||
use reqwest::Method; | ||
use tower_http::{ | ||
cors::{Any, CorsLayer}, | ||
trace::TraceLayer, | ||
}; | ||
|
||
static APP: OnceLock<Router> = OnceLock::new(); | ||
|
||
pub fn init() { | ||
let cors = CorsLayer::new() | ||
.allow_methods([Method::GET, Method::POST, Method::PUT, Method::DELETE, Method::OPTIONS]) | ||
.allow_headers(Any) | ||
.allow_origin(Any); | ||
|
||
let app: Router = Router::new() | ||
.merge(Router::new().nest("/api", router::router()).layer(TraceLayer::new_for_http())) | ||
.layer(from_fn(middleware::frontend::serve)) | ||
.layer(cors); | ||
|
||
APP.set(app).unwrap(); | ||
} | ||
|
||
pub fn get_app() -> Router { | ||
return APP.get().unwrap().clone(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
src/server/router/submission.rs → src/web/router/submission.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.