cors and LISTEN env
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -58,7 +58,11 @@ async fn main() -> anyhow::Result<()> {
|
||||
let app = axum::Router::new()
|
||||
.fallback(get(api_proxy_image))
|
||||
.with_state(downloader);
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:2999").await?;
|
||||
|
||||
let listen = std::env::var("LISTEN").unwrap_or("0.0.0.0:2999".to_string());
|
||||
println!("listening on: {}", listen);
|
||||
let listener = tokio::net::TcpListener::bind(&listen).await?;
|
||||
|
||||
axum::serve(listener, app).await?;
|
||||
|
||||
Ok(())
|
||||
@@ -140,6 +144,12 @@ async fn api_proxy_image(
|
||||
|
||||
Ok(Response::builder()
|
||||
.header("Content-Type", "image/webp")
|
||||
.header("Cache-Control", "public, max-age=31536000")
|
||||
.header("Access-Control-Allow-Origin", "*")
|
||||
.header("Access-Control-Allow-Methods", "GET")
|
||||
.header("Access-Control-Allow-Headers", "Content-Type")
|
||||
.header("Access-Control-Max-Age", "86400")
|
||||
.header("X-Original-Url", target_url)
|
||||
.header("X-Original-Content-Type", ori_content_type)
|
||||
.header("X-Original-Size", original_size.to_string())
|
||||
.header("X-Original-Width", ori_width.to_string())
|
||||
|
||||
Reference in New Issue
Block a user