Skip to content

Commit

Permalink
feat: allow headers and all methods in the request (#644)
Browse files Browse the repository at this point in the history
* allow headers in the request

* resovle conflicts

* allow methods
  • Loading branch information
ravi-sawlani-yral authored Jan 31, 2025
1 parent c9eecb0 commit 86ab4c8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ssr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use hot_or_not_web_leptos_ssr::{
use leptos::{get_configuration, logging::log, provide_context};
use leptos_axum::handle_server_fns_with_context;
use leptos_axum::{generate_route_list, LeptosRoutes};
use tower_http::cors::{AllowOrigin, CorsLayer};
use tower_http::cors::{AllowOrigin, Any, CorsLayer};

pub async fn server_fn_handler(
State(app_state): State<AppState>,
Expand Down Expand Up @@ -144,13 +144,16 @@ async fn main() {
get(server_fn_handler).post(server_fn_handler),
)
.layer(
CorsLayer::new().allow_origin(AllowOrigin::predicate(|origin, _| {
if let Ok(host) = origin.to_str() {
is_host_or_origin_from_preview_domain(host) || host == "yral.com"
} else {
false
}
})),
CorsLayer::new()
.allow_headers(Any)
.allow_methods(Any)
.allow_origin(AllowOrigin::predicate(|origin, _| {
if let Ok(host) = origin.to_str() {
is_host_or_origin_from_preview_domain(host) || host == "yral.com"
} else {
false
}
})),
)
.leptos_routes_with_handler(routes, get(leptos_routes_handler))
.fallback(file_and_error_handler)
Expand Down

0 comments on commit 86ab4c8

Please sign in to comment.