Skip to content

feat: add cors config for orion#1377

Merged
genedna merged 1 commit into
gitmono-dev:mainfrom
benjamin-747:main
Aug 26, 2025
Merged

feat: add cors config for orion#1377
genedna merged 1 commit into
gitmono-dev:mainfrom
benjamin-747:main

Conversation

@benjamin-747

Copy link
Copy Markdown
Collaborator

No description provided.

@benjamin-747
benjamin-747 requested a review from genedna August 26, 2025 07:14
@benjamin-747 benjamin-747 self-assigned this Aug 26, 2025
@vercel

vercel Bot commented Aug 26, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
mega Ready Ready Preview Comment Aug 26, 2025 7:15am

@genedna
genedna added this pull request to the merge queue Aug 26, 2025
Merged via the queue into gitmono-dev:main with commit d22fa09 Aug 26, 2025
12 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds CORS (Cross-Origin Resource Sharing) configuration to the Orion server to allow cross-origin requests from specified domains. This enables the server to be accessed by web applications running on different origins.

  • Configures CORS middleware with environment-variable driven allowed origins
  • Adds support for common HTTP methods and headers including credentials
  • Updates dependencies to include required CORS functionality

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
orion-server/src/server.rs Implements CORS middleware configuration with environment-based origin allowlist
orion-server/Cargo.toml Adds required dependencies for CORS and HTTP functionality
orion-server/.env Defines allowed CORS origins for local and production environments

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +64 to +68
let origins: Vec<HeaderValue> = std::env::var("ALLOWED_CORS_ORIGINS")
.unwrap()
.split(',')
.map(|x| x.trim().parse::<HeaderValue>().unwrap())
.collect();

Copilot AI Aug 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code will panic if the ALLOWED_CORS_ORIGINS environment variable is not set or if any origin cannot be parsed as a HeaderValue. Consider using proper error handling with expect() or unwrap_or_default() and handling parse errors gracefully.

Suggested change
let origins: Vec<HeaderValue> = std::env::var("ALLOWED_CORS_ORIGINS")
.unwrap()
.split(',')
.map(|x| x.trim().parse::<HeaderValue>().unwrap())
.collect();
let origins: Vec<HeaderValue> = match std::env::var("ALLOWED_CORS_ORIGINS") {
Ok(val) => val
.split(',')
.filter_map(|x| {
let trimmed = x.trim();
match HeaderValue::from_str(trimmed) {
Ok(hv) => Some(hv),
Err(e) => {
tracing::warn!("Invalid CORS origin '{}': {}", trimmed, e);
None
}
}
})
.collect(),
Err(e) => {
tracing::error!("ALLOWED_CORS_ORIGINS environment variable is not set: {}", e);
std::process::exit(1);
}
};

Copilot uses AI. Check for mistakes.
Comment thread orion-server/.env
PORT=80
MONOBASE_URL="http://git.gitmega.com" No newline at end of file
MONOBASE_URL="http://git.gitmega.com"
ALLOWED_CORS_ORIGINS = "http://local.gitmega.com, https://app.gitmega.com, http://app.gitmono.test" No newline at end of file

Copilot AI Aug 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Environment variable assignments should not have spaces around the equals sign. Change to ALLOWED_CORS_ORIGINS=\"http://local.gitmega.com, https://app.gitmega.com, http://app.gitmono.test\"

Suggested change
ALLOWED_CORS_ORIGINS = "http://local.gitmega.com, https://app.gitmega.com, http://app.gitmono.test"
ALLOWED_CORS_ORIGINS="http://local.gitmega.com, https://app.gitmega.com, http://app.gitmono.test"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants