Add CORS
This commit is contained in:
parent
f4d6fdf146
commit
33426a6cd6
15
src/main.rs
15
src/main.rs
@ -1,3 +1,4 @@
|
||||
use actix_cors::Cors;
|
||||
use actix_web::{App, HttpResponse, HttpServer, Responder, web};
|
||||
use clap::Parser;
|
||||
use env_logger::Env;
|
||||
@ -5,7 +6,7 @@ use env_logger::Env;
|
||||
use sea_battle_backend::data::{GameRules, PlayConfiguration};
|
||||
|
||||
/// Simple sea battle server
|
||||
#[derive(Parser, Debug)]
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// The address this server will listen to
|
||||
@ -43,10 +44,20 @@ async fn main() -> std::io::Result<()> {
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
|
||||
let args: Args = Args::parse();
|
||||
let args_clone = args.clone();
|
||||
|
||||
HttpServer::new(move || {
|
||||
|
||||
let mut cors = Cors::default();
|
||||
match args_clone.cors.as_deref() {
|
||||
Some("*") => cors = cors.allow_any_origin(),
|
||||
Some(orig) => cors = cors.allowed_origin(orig),
|
||||
None => {}
|
||||
}
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(cors)
|
||||
|
||||
.route("/bot/config", web::get().to(bot_configuration))
|
||||
|
||||
.route("/random/config", web::get().to(multi_players_config))
|
||||
|
Loading…
Reference in New Issue
Block a user