Skip to content

Commit

Permalink
feat: add cargo dependency tower-http
Browse files Browse the repository at this point in the history
With the new Axum implementation for the API the browser does not make
request to the API becuase of the Cross-Origin Resource Sharing (CORS)
policy. By default there is no header `Access-Control-Allow-Origin` and
it does not allow the request.

You can be permissive by adding a layer to the router:

```
Router::new().nest("/v1", api_routes).layer(CorsLayer::permissive())
```

For the time being you need to change that line manually when you want
to setup a dev env with the banckend and the frontend using different
ports.
  • Loading branch information
josecelano committed Jun 13, 2023
1 parent 79682a5 commit 91522f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 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 @@ -48,6 +48,7 @@ thiserror = "1.0"
binascii = "0.1"
axum = "0.6.18"
hyper = "0.14.26"
tower-http = { version = "0.4.0", features = ["cors"]}

[dev-dependencies]
rand = "0.8"
Expand Down

0 comments on commit 91522f4

Please sign in to comment.