remove cors layer
This commit is contained in:
26
src/main.rs
26
src/main.rs
@@ -1,8 +1,7 @@
|
||||
mod board;
|
||||
mod game;
|
||||
use std::env;
|
||||
|
||||
use axum::{http::Method, Router};
|
||||
use axum::Router;
|
||||
use board::Board;
|
||||
use dotenv::dotenv;
|
||||
use futures_util::stream::StreamExt;
|
||||
@@ -18,8 +17,6 @@ use socketioxide::{
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
use tokio::net::TcpListener;
|
||||
use tower_http::cors::{AllowOrigin, CorsLayer};
|
||||
use tracing::warn;
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
#[tokio::main]
|
||||
@@ -37,27 +34,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let (layer, io) = SocketIo::builder().with_state(pool).build_layer();
|
||||
|
||||
io.ns("/", on_connect);
|
||||
// Get the allowed origins from the .env file
|
||||
let allowed_origins = env::var("ALLOWED_ORIGINS").unwrap_or_else(|_| {
|
||||
warn!("ALLOWED_ORIGINS not found in .env, defaulting to http://localhost:5173");
|
||||
"http://localhost:5173".to_string()
|
||||
});
|
||||
|
||||
// Split the origins by comma and collect them into a vector
|
||||
let origins: Vec<String> = allowed_origins
|
||||
.split(',')
|
||||
.map(|s| s.trim().to_string())
|
||||
.collect();
|
||||
|
||||
// Convert the vector of strings into `AllowOrigin`
|
||||
let allow_origin = AllowOrigin::list(origins.iter().map(|origin| origin.parse().unwrap()));
|
||||
|
||||
// Create a CORS layer
|
||||
let cors = CorsLayer::new()
|
||||
.allow_origin(allow_origin)
|
||||
.allow_methods([Method::GET, Method::POST]);
|
||||
|
||||
let app = Router::new().layer(layer).layer(cors);
|
||||
let app = Router::new().layer(layer);
|
||||
|
||||
let listener = TcpListener::bind("0.0.0.0:3000").await?;
|
||||
println!("listening on {}", listener.local_addr()?);
|
||||
|
Reference in New Issue
Block a user