Skip to content

Commit 6a22c6d

Browse files
committed
cors fix
rate limit fix
1 parent 288c059 commit 6a22c6d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

packages/server/.env.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
DATABASE_URL=
2-
JWT_SECRET=
2+
JWT_SECRET=
3+
CLIENT_URL=

packages/server/src/app.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
use crate::{error::ApiError, routes};
2-
use axum::{http::StatusCode, routing, Extension, Json, Router};
2+
use axum::{
3+
http::{
4+
header::{AUTHORIZATION, CONTENT_TYPE},
5+
StatusCode,
6+
},
7+
routing, Extension, Json, Router,
8+
};
39
use serde_json::json;
410
use sqlx::postgres::{PgPool, PgPoolOptions};
511
use std::{net::SocketAddr, sync::Arc, time::Duration};
@@ -28,15 +34,19 @@ pub async fn app() {
2834

2935
let state = ServiceBuilder::new().layer(Extension(AppState { db: Arc::new(db) }));
3036

37+
let client_url = &*std::env::var("CLIENT_URL")
38+
.ok()
39+
.unwrap_or("http://localhost:3000".to_string());
40+
3141
// [TODO]: Change this to only allow the frontend domain
3242
let cors = CorsLayer::new()
33-
.allow_headers(Any)
43+
.allow_headers([AUTHORIZATION, CONTENT_TYPE])
3444
.allow_methods(Any)
35-
.allow_origin(Any);
45+
.allow_origin([client_url.parse().unwrap()]);
3646

3747
let governor_conf = Box::new(
3848
GovernorConfigBuilder::default()
39-
.per_second(2)
49+
.per_second(1)
4050
.burst_size(15)
4151
.finish()
4252
.unwrap(),

0 commit comments

Comments
 (0)