Skip to content

Commit 91522f4

Browse files
committed
feat: add cargo dependency tower-http
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.
1 parent 79682a5 commit 91522f4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Cargo.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ thiserror = "1.0"
4848
binascii = "0.1"
4949
axum = "0.6.18"
5050
hyper = "0.14.26"
51+
tower-http = { version = "0.4.0", features = ["cors"]}
5152

5253
[dev-dependencies]
5354
rand = "0.8"

0 commit comments

Comments
 (0)