Disable cors
This commit is contained in:
@@ -1 +1,2 @@
|
||||
/target
|
||||
/.idea
|
||||
Generated
+17
@@ -324,6 +324,7 @@ dependencies = [
|
||||
"axum",
|
||||
"rand",
|
||||
"tokio",
|
||||
"tower-http",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -682,6 +683,22 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-http"
|
||||
version = "0.6.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bytes",
|
||||
"http",
|
||||
"http-body",
|
||||
"pin-project-lite",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-layer"
|
||||
version = "0.3.3"
|
||||
|
||||
+2
-1
@@ -6,4 +6,5 @@ edition = "2024"
|
||||
[dependencies]
|
||||
axum = { version = "0.8.9", features = ["multipart", ] }
|
||||
tokio = { version = "1.52.3", features = ["full"] }
|
||||
rand = "0.10.1"
|
||||
rand = "0.10.1"
|
||||
tower-http = {version = "0.6.6", features = ["cors", "trace"]}
|
||||
+8
-1
@@ -1,5 +1,7 @@
|
||||
use axum::extract::{DefaultBodyLimit, Path};
|
||||
use axum::http::StatusCode;
|
||||
use axum::http::Method;
|
||||
|
||||
use axum::response::IntoResponse;
|
||||
use axum::routing::post;
|
||||
use axum::{extract::Multipart, routing::get, Router};
|
||||
@@ -8,17 +10,22 @@ use rand::rng;
|
||||
use std::os::unix::prelude::MetadataExt;
|
||||
use std::path::PathBuf;
|
||||
use tokio::fs::File;
|
||||
use tower_http::cors::{Any, CorsLayer};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
ensure_work_dir();
|
||||
let cors = CorsLayer::new()
|
||||
.allow_origin(Any)
|
||||
.allow_methods(vec![Method::GET, Method::POST]).allow_headers(Any);
|
||||
|
||||
let app = Router::new()
|
||||
.route("/generate", get(generate_id))
|
||||
.route("/upload/{id}", post(upload_file))
|
||||
.route("/download/{id}", get(download_file))
|
||||
.route("/{id}/version", get(version))
|
||||
.layer(DefaultBodyLimit::max(50 * 1024 * 1024));
|
||||
.layer(DefaultBodyLimit::max(50 * 1024 * 1024))
|
||||
.layer(cors);
|
||||
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:8089").await.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user