Skip to content

Commit

Permalink
Merge pull request #83 from Nuhvi/fix/cors-very-permissive
Browse files Browse the repository at this point in the history
Fix/cors very permissive
Nuhvi authored Oct 4, 2024
2 parents a801f79 + 4fe6960 commit 6105246
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target/
config.toml
14 changes: 13 additions & 1 deletion server/README.md
Original file line number Diff line number Diff line change
@@ -11,8 +11,20 @@ Build
cargo build --release
```

Optinally Copy config file

```bash
cp src/config.example.toml config.toml
```

Run with an optional config file

```bash
../target/release/pkarr-server --config=./src/config.toml
../target/release/pkarr-server --config=./config.toml
```

You can customize logging levels

```bash
../target/release/pkarr-server --config=./config.toml -t=pkarr=debug,tower_http=debug
```
File renamed without changes.
10 changes: 3 additions & 7 deletions server/src/http_server.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use anyhow::Result;
use axum::extract::DefaultBodyLimit;
use axum::{http::Method, routing::get, Router};
use axum::{routing::get, Router};
use std::net::SocketAddr;
use tokio::{net::TcpListener, task::JoinSet};
use tower_http::cors::{self, CorsLayer};
use tower_http::cors::CorsLayer;
use tower_http::trace::TraceLayer;
use tracing::{info, warn};

@@ -76,10 +76,6 @@ impl HttpServer {
}

pub fn create_app(state: AppState, rate_limiter: IpRateLimiter) -> Router {
let cors = CorsLayer::new()
.allow_methods([Method::GET, Method::PUT])
.allow_origin(cors::Any);

let router = Router::new()
.route("/:key", get(crate::handlers::get).put(crate::handlers::put))
.route(
@@ -88,7 +84,7 @@ pub fn create_app(state: AppState, rate_limiter: IpRateLimiter) -> Router {
)
.with_state(state)
.layer(DefaultBodyLimit::max(1104))
.layer(cors)
.layer(CorsLayer::very_permissive())
.layer(TraceLayer::new_for_http());

rate_limiter.layer(router)

0 comments on commit 6105246

Please sign in to comment.