Skip to content

Commit

Permalink
Merge pull request #28 from polywrap/nerfzael-cors
Browse files Browse the repository at this point in the history
Cors
  • Loading branch information
nerfZael authored Sep 3, 2023
2 parents d23ef31 + 55b2e4f commit d9a72d3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
27 changes: 26 additions & 1 deletion gateway/Cargo.lock

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

3 changes: 2 additions & 1 deletion gateway/rust/gateway_service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gateway_service"
version = "0.1.4"
version = "0.1.5"
edition = "2021"

[dependencies]
Expand Down Expand Up @@ -30,6 +30,7 @@ tower-service = "0.3.2"
dotenvy = "0.15.7"
clap = { version = "4.3.10", features = ["derive"] }
polywrap_core = "0.1.6-beta.7"
tower-http = { version = "0.4.3", features = ["cors"] }

[dev-dependencies]
mockall = "0.11.4"
Expand Down
11 changes: 9 additions & 2 deletions gateway/rust/gateway_service/src/setup_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use axum::{
routing::{get, post},
Router,
};
use http::Method;
use lambda_http::{run, Error as HttpError};
use tower_http::cors::{Any, CorsLayer};

use crate::{
constants,
Expand Down Expand Up @@ -51,6 +53,11 @@ pub async fn setup_routes() -> Result<(), HttpError> {
}
};

let cors = CorsLayer::new()
.allow_headers(Any)
.allow_methods(vec![Method::GET, Method::POST, Method::OPTIONS, Method::HEAD, Method::PUT, Method::DELETE])
.allow_origin(Any);

let app = Router::new()
.route(
&(route_prefix.clone() + "/"),
Expand All @@ -71,7 +78,7 @@ pub async fn setup_routes() -> Result<(), HttpError> {
.route(
&(route_prefix + "/r/:user/:packageAndVersion"),
post(routes::publish).with_state(deps),
);
).layer(cors);

#[cfg(not(feature = "local"))]
{
Expand All @@ -80,7 +87,7 @@ pub async fn setup_routes() -> Result<(), HttpError> {

#[cfg(feature = "local")]
{
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 3000));
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 3001));
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
Expand Down

0 comments on commit d9a72d3

Please sign in to comment.