Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion orion-server/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
BUILD_LOG_DIR="/tmp/megadir/buck2ctl"
DATABASE_URL="postgres://postgres:postgres@localhost/orion"
PORT=80
MONOBASE_URL="http://git.gitmega.com"
MONOBASE_URL="http://git.gitmega.com"
ALLOWED_CORS_ORIGINS = "http://local.gitmega.com, https://app.gitmega.com, http://app.gitmono.test"

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.
8 changes: 5 additions & 3 deletions orion-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ version = "0.1.0"
edition = "2024"

[dependencies]
orion = { workspace = true}
orion = { workspace = true }

http = { workspace = true }
axum = { workspace = true, features = ["macros", "ws"] }
axum-extra = { workspace = true, features = ["erased-json"] }
tokio = { workspace = true, features = ["rt-multi-thread", "fs", "process"] }
Expand All @@ -16,7 +17,8 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
futures-util = { workspace = true }
uuid = { workspace = true, features = ["v7"] }
tower-http = { workspace = true, features = ["trace"] }
tower-http = { workspace = true, features = ["trace", "cors"] }
tower = { workspace = true }
sea-orm = { workspace = true, features = [
"sqlx-postgres",
"runtime-tokio-rustls",
Expand All @@ -35,4 +37,4 @@ reqwest.workspace = true
thiserror = "2.0"

[dev-dependencies]
tempfile = "3"
tempfile = "3"
38 changes: 33 additions & 5 deletions orion-server/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
use crate::api::{self, AppState};
use crate::model::builds;
use std::net::SocketAddr;
use std::time::Duration;

use axum::Router;
use axum::routing::get;
use http::{HeaderValue, Method};
use sea_orm::{
ActiveValue::Set, ColumnTrait, ConnectionTrait, Database, DatabaseConnection, DbErr,
EntityTrait, QueryFilter, Schema, TransactionTrait,
};
use std::net::SocketAddr;
use std::time::Duration;
use tower::ServiceBuilder;
use tower_http::cors::CorsLayer;
use tower_http::trace::TraceLayer;
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;

use crate::api::{self, AppState};
use crate::model::builds;
/// OpenAPI documentation configuration
#[derive(OpenApi)]
#[openapi(
Expand Down Expand Up @@ -57,12 +61,36 @@ pub async fn start_server(port: u16) {
// Start queue manager
tokio::spawn(api::start_queue_manager(state.clone()));

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

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.

let app = Router::new()
.route("/", get(|| async { "Hello, World!" }))
.merge(api::routers())
.merge(SwaggerUi::new("/swagger-ui").url("/api-doc/openapi.json", ApiDoc::openapi()))
.with_state(state)
.layer(TraceLayer::new_for_http());
.layer(TraceLayer::new_for_http())
.layer(
ServiceBuilder::new().layer(
CorsLayer::new()
.allow_origin(origins)
.allow_headers(vec![
http::header::AUTHORIZATION,
http::header::CONTENT_TYPE,
])
.allow_methods([
Method::GET,
Method::POST,
Method::OPTIONS,
Method::DELETE,
Method::PUT,
])
.allow_credentials(true),
),
);

tracing::info!("Listening on port {}", port);
let addr = tokio::net::TcpListener::bind(&format!("0.0.0.0:{port}"))
Expand Down
Loading