Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/cors very permissive #83

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -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};

Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
Loading