fix: add CORS origin environment variable (#3191)

* fix: add CORS origin environment variable

* chore: formatting

---------

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
This commit is contained in:
Andrew DeLisa 2023-06-20 08:29:38 -04:00 committed by GitHub
parent 06a3f9c5aa
commit bfc0c0e7d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -50,6 +50,8 @@ services:
- lemmyexternalproxy - lemmyexternalproxy
restart: always restart: always
environment: 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_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 - RUST_BACKTRACE=full
volumes: volumes:

View File

@ -150,10 +150,12 @@ pub async fn start_lemmy_server() -> Result<(), LemmyError> {
.build() .build()
.expect("configure federation"); .expect("configure federation");
let cors_origin = std::env::var("LEMMY_CORS_ORIGIN").unwrap_or_default();
let cors_config = if cfg!(debug_assertions) { let cors_config = if cfg!(debug_assertions) {
Cors::permissive() Cors::permissive()
} else { } else {
Cors::default() Cors::default().allowed_origin(&cors_origin)
}; };
App::new() App::new()