Skip to content

Commit

Permalink
add cors
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Mar 4, 2024
1 parent d76c0b7 commit a0edcc9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ semver = "1.0.21"
clap = { version = "4.5.1", features = ["derive"] }
regex = "1.10.3"
chrono = "0.4.34"
actix-cors = "0.7.0"
15 changes: 15 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use actix_cors::Cors;
use actix_web::{
get,
http::header,
middleware::Logger,
web::{self, QueryConfig},
App, HttpServer, Responder,
Expand Down Expand Up @@ -77,12 +79,25 @@ async fn main() -> anyhow::Result<()> {
log::info!("Job {} completed", s);
return anyhow::Ok(());
}
let cors = Cors::default()
.allow_any_origin()
.allow_any_method()
.allow_any_header()
.max_age(3600);

info!("Starting server on {}:{}", addr, port);
let server = HttpServer::new(move || {
App::new()
.app_data(web::Data::new(app_data.clone()))
.app_data(QueryConfig::default().error_handler(api::query_error_handler))
.wrap(
Cors::default()
.allow_any_origin()
.allowed_methods(vec!["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"])
.allow_any_header()
.supports_credentials()
.max_age(3600),
)
.wrap(Logger::default())
.service(endpoints::mods::index)
.service(endpoints::mods::get_mod_updates)
Expand Down

0 comments on commit a0edcc9

Please sign in to comment.