From bfc0c0e7d37a01aa498ff94cfb0ff1663fce65dc Mon Sep 17 00:00:00 2001 From: Andrew DeLisa Date: Tue, 20 Jun 2023 08:29:38 -0400 Subject: [PATCH] fix: add CORS origin environment variable (#3191) * fix: add CORS origin environment variable * chore: formatting --------- Co-authored-by: Dessalines --- docker/docker-compose.yml | 2 ++ src/lib.rs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index b3b3b8b38..74323d98c 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -50,6 +50,8 @@ services: - lemmyexternalproxy restart: always environment: + # set this to the public origin that requests will come from + - LEMMY_CORS_ORIGIN=http://localhost - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug" - RUST_BACKTRACE=full volumes: diff --git a/src/lib.rs b/src/lib.rs index 7179f2197..d8d367fb3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -150,10 +150,12 @@ pub async fn start_lemmy_server() -> Result<(), LemmyError> { .build() .expect("configure federation"); + let cors_origin = std::env::var("LEMMY_CORS_ORIGIN").unwrap_or_default(); + let cors_config = if cfg!(debug_assertions) { Cors::permissive() } else { - Cors::default() + Cors::default().allowed_origin(&cors_origin) }; App::new()