Skip to content

Commit

Permalink
Allow cross-origin requests (#3421)
Browse files Browse the repository at this point in the history
Co-authored-by: pfg <pfg@pfg.pw>
  • Loading branch information
diamondburned and pfgithub committed Jul 6, 2023
1 parent 6840fd6 commit 084f603
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,17 @@ pub async fn start_lemmy_server() -> Result<(), LemmyError> {

// Create Http server with websocket support
HttpServer::new(move || {
let cors_config = if cfg!(debug_assertions) {
Cors::permissive()
} else {
let cors_origin = std::env::var("LEMMY_CORS_ORIGIN").unwrap_or("http://localhost".into());
Cors::default()
.allowed_origin(&cors_origin)
.allowed_origin(&settings.get_protocol_and_hostname())
let cors_origin = std::env::var("LEMMY_CORS_ORIGIN");
let cors_config = match (cors_origin, cfg!(debug_assertions)) {
(Ok(origin), false) => Cors::default()
.allowed_origin(&origin)
.allowed_origin(&settings.get_protocol_and_hostname()),
_ => Cors::default()
.allow_any_origin()
.allow_any_method()
.allow_any_header()
.expose_any_header()
.max_age(3600),
};

let app = App::new()
Expand Down

0 comments on commit 084f603

Please sign in to comment.