Create a tiny server for testing the Fetch API
This commit is contained in:
parent
f6534d5d05
commit
e9f89e1bdb
@ -4,3 +4,6 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
axum = "0.8.1"
|
||||
tokio = { version = "1.43.0", features = ["full", "rt"] }
|
||||
tower-http = { version = "0.6.2", features = ["cors"] }
|
||||
|
@ -1,3 +1,26 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use axum::{http::{Method, StatusCode}, routing::get, Json, Router};
|
||||
use tower_http::cors::{Any, CorsLayer};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let app = Router::new()
|
||||
.route(
|
||||
"/api/v1/health",
|
||||
get(|| async { (StatusCode::OK, Json(None::<String>)) }),
|
||||
).layer(
|
||||
CorsLayer::new()
|
||||
.allow_methods([Method::GET]).allow_origin(Any),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/denied",
|
||||
get(|| async { (StatusCode::UNAUTHORIZED, Json(None::<String>)) }),
|
||||
).layer(
|
||||
CorsLayer::new()
|
||||
.allow_methods([Method::GET]).allow_origin(Any),
|
||||
);
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:8001")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user