Disable cors
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
/.idea
|
||||||
Generated
+17
@@ -324,6 +324,7 @@ dependencies = [
|
|||||||
"axum",
|
"axum",
|
||||||
"rand",
|
"rand",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tower-http",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -682,6 +683,22 @@ dependencies = [
|
|||||||
"tracing",
|
"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]]
|
[[package]]
|
||||||
name = "tower-layer"
|
name = "tower-layer"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
|
|||||||
@@ -7,3 +7,4 @@ edition = "2024"
|
|||||||
axum = { version = "0.8.9", features = ["multipart", ] }
|
axum = { version = "0.8.9", features = ["multipart", ] }
|
||||||
tokio = { version = "1.52.3", features = ["full"] }
|
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::extract::{DefaultBodyLimit, Path};
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
|
use axum::http::Method;
|
||||||
|
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::routing::post;
|
use axum::routing::post;
|
||||||
use axum::{extract::Multipart, routing::get, Router};
|
use axum::{extract::Multipart, routing::get, Router};
|
||||||
@@ -8,17 +10,22 @@ use rand::rng;
|
|||||||
use std::os::unix::prelude::MetadataExt;
|
use std::os::unix::prelude::MetadataExt;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
|
use tower_http::cors::{Any, CorsLayer};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
ensure_work_dir();
|
ensure_work_dir();
|
||||||
|
let cors = CorsLayer::new()
|
||||||
|
.allow_origin(Any)
|
||||||
|
.allow_methods(vec![Method::GET, Method::POST]).allow_headers(Any);
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/generate", get(generate_id))
|
.route("/generate", get(generate_id))
|
||||||
.route("/upload/{id}", post(upload_file))
|
.route("/upload/{id}", post(upload_file))
|
||||||
.route("/download/{id}", get(download_file))
|
.route("/download/{id}", get(download_file))
|
||||||
.route("/{id}/version", get(version))
|
.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();
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:8089").await.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user