Saving changes
Rust Build / Rustfmt (pull_request) Successful in 40s
Rust Build / Test Suite (pull_request) Failing after 1m39s
Rust Build / Clippy (pull_request) Failing after 1m20s
Rust Build / Check (pull_request) Failing after 2m28s
Rust Build / build (pull_request) Failing after 1m59s

This commit is contained in:
2026-06-13 14:52:34 -04:00
parent f29c876ad6
commit 93ab1d5db0
2 changed files with 98 additions and 98 deletions
+97 -97
View File
@@ -1,4 +1,3 @@
pub mod host { pub mod host {
pub const PORT: i64 = 9081; pub const PORT: i64 = 9081;
@@ -10,116 +9,117 @@ pub mod host {
pub mod init { pub mod init {
use std::time::Duration; use std::time::Duration;
use axum::routing::{delete, get, patch, post}; use axum::routing::{delete, get, patch, post};
use tower_http::timeout::TimeoutLayer; use tower_http::timeout::TimeoutLayer;
use utoipa::OpenApi; use utoipa::OpenApi;
use crate::callers::coverart as coverart_caller; use crate::callers::coverart as coverart_caller;
use crate::callers::queue::coverart as coverart_queue_callers; use crate::callers::queue::coverart as coverart_queue_callers;
use crate::callers::queue::metadata as metadata_queue_caller; use crate::callers::queue::metadata as metadata_queue_caller;
use crate::callers::queue::song as song_queue_callers; use crate::callers::queue::song as song_queue_callers;
use crate::callers::song as song_caller; use crate::callers::song as song_caller;
use coverart_caller::endpoint as coverart_endpoints; use coverart_caller::endpoint as coverart_endpoints;
use coverart_caller::response as coverart_responses; use coverart_caller::response as coverart_responses;
use coverart_queue_callers::endpoint as coverart_queue_endpoints; use coverart_queue_callers::endpoint as coverart_queue_endpoints;
use coverart_queue_callers::response as coverart_queue_responses; use coverart_queue_callers::response as coverart_queue_responses;
use metadata_queue_caller::endpoint as metadata_queue_endpoints; use metadata_queue_caller::endpoint as metadata_queue_endpoints;
use metadata_queue_caller::response as metadata_queue_responses; use metadata_queue_caller::response as metadata_queue_responses;
use song_caller::endpoint as song_endpoints; use song_caller::endpoint as song_endpoints;
use song_caller::response as song_responses; use song_caller::response as song_responses;
use song_queue_callers::endpoint as song_queue_endpoints; use song_queue_callers::endpoint as song_queue_endpoints;
use song_queue_callers::response as song_queue_responses; use song_queue_callers::response as song_queue_responses;
mod cors { mod cors {
pub async fn configure_cors() -> tower_http::cors::CorsLayer { pub async fn configure_cors() -> tower_http::cors::CorsLayer {
let cors = tower_http::cors::CorsLayer::new() let cors = tower_http::cors::CorsLayer::new()
.allow_methods([ .allow_methods([
axum::http::Method::GET, axum::http::Method::GET,
axum::http::Method::POST, axum::http::Method::POST,
axum::http::Method::PUT, axum::http::Method::PUT,
axum::http::Method::DELETE, axum::http::Method::DELETE,
]) // Specify allowed methods:cite[2] ]) // Specify allowed methods:cite[2]
.allow_headers([ .allow_headers([
axum::http::header::CONTENT_TYPE, axum::http::header::CONTENT_TYPE,
axum::http::header::AUTHORIZATION, axum::http::header::AUTHORIZATION,
]) // Specify allowed headers:cite[2] ]) // Specify allowed headers:cite[2]
.allow_credentials(true) // If you need to send cookies or authentication headers:cite[2] .allow_credentials(true) // If you need to send cookies or authentication headers:cite[2]
.max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2] .max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2]
// Dynamically set the allowed origin based on the environment // Dynamically set the allowed origin based on the environment
match std::env::var(textsender_models::envy::keys::APP_ENV).as_deref() { match std::env::var(textsender_models::envy::keys::APP_ENV).as_deref() {
Ok("production") => { Ok("production") => {
// In production, allow only your specific, trusted origins // In production, allow only your specific, trusted origins
let allowed_origins_env = textsender_models::envy::environment::get_allowed_origins().await; let allowed_origins_env =
match textsender_models::envy::utility::delimitize(&allowed_origins_env) { textsender_models::envy::environment::get_allowed_origins().await;
Ok(alwd) => { match textsender_models::envy::utility::delimitize(&allowed_origins_env) {
let allowed_origins: Vec<axum::http::HeaderValue> = alwd Ok(alwd) => {
.into_iter() let allowed_origins: Vec<axum::http::HeaderValue> = alwd
.map(|a| a.parse::<axum::http::HeaderValue>().unwrap()) .into_iter()
.collect(); .map(|a| a.parse::<axum::http::HeaderValue>().unwrap())
cors.allow_origin(allowed_origins) .collect();
} cors.allow_origin(allowed_origins)
Err(err) => { }
eprintln!("Error getting allowed origins: Error: {err:?}"); Err(err) => {
std::process::exit(-1); eprintln!("Error getting allowed origins: Error: {err:?}");
std::process::exit(-1);
}
} }
} }
} _ => {
_ => { // Development (default): Allow localhost origins
// Development (default): Allow localhost origins cors.allow_origin(vec![
cors.allow_origin(vec![ "http://localhost:8000".parse().unwrap(),
"http://localhost:8000".parse().unwrap(), "http://127.0.0.1:8000".parse().unwrap(),
"http://127.0.0.1:8000".parse().unwrap(), "http://localhost:4200".parse().unwrap(),
"http://localhost:4200".parse().unwrap(), "http://127.0.0.1:4200".parse().unwrap(),
"http://127.0.0.1:4200".parse().unwrap(), ])
]) }
} }
} }
} }
}
#[derive(utoipa::OpenApi)] #[derive(utoipa::OpenApi)]
#[openapi( #[openapi(
paths(song_queue_endpoints::queue_song,), paths(song_queue_endpoints::queue_song,),
components(schemas(song_queue_callers::response::song_queue::Response)), components(schemas(song_queue_callers::response::song_queue::Response)),
tags( tags(
(name = "textsender API", description = "Web API to manage texting") (name = "textsender API", description = "Web API to manage texting")
) )
)] )]
struct ApiDoc; struct ApiDoc;
pub async fn routes() -> axum::Router { pub async fn routes() -> axum::Router {
axum::Router::new() axum::Router::new()
.route( .route(
crate::callers::queue::endpoints::QUEUESONG, crate::callers::queue::endpoints::QUEUESONG,
post(crate::callers::queue::song::endpoint::queue_song).route_layer( post(crate::callers::queue::song::endpoint::queue_song).route_layer(
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>), axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
), ),
) )
.layer(cors::configure_cors().await) .layer(cors::configure_cors().await)
} }
pub async fn app() -> axum::Router { pub async fn app() -> axum::Router {
let pool = crate::db::create_pool() let pool = crate::db::create_pool()
.await .await
.expect("Failed to create pool"); .expect("Failed to create pool");
crate::db::migrations(&pool).await; crate::db::migrations(&pool).await;
let cors = cors::configure_cors().await; let cors = cors::configure_cors().await;
routes() routes()
.await .await
.merge( .merge(
utoipa_swagger_ui::SwaggerUi::new("/swagger-ui") utoipa_swagger_ui::SwaggerUi::new("/swagger-ui")
.url("/api-docs/openapi.json", ApiDoc::openapi()), .url("/api-docs/openapi.json", ApiDoc::openapi()),
) )
.layer(axum::Extension(pool)) .layer(axum::Extension(pool))
.layer(axum::extract::DefaultBodyLimit::max(1024 * 1024 * 1024)) .layer(axum::extract::DefaultBodyLimit::max(1024 * 1024 * 1024))
.layer(TimeoutLayer::with_status_code( .layer(TimeoutLayer::with_status_code(
axum::http::StatusCode::OK, axum::http::StatusCode::OK,
Duration::from_secs(300), Duration::from_secs(300),
)) ))
.layer(cors) .layer(cors)
} }
} }
+1 -1
View File
@@ -3,7 +3,7 @@ async fn main() {
// initialize tracing // initialize tracing
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
match tokio::net::TcpListener::bind(textsender_api::config::host::get_full()).await { match tokio::net::TcpListener::bind(textsender_api::config::host::get_full()).await {
Ok(listener) => { Ok(listener) => {
// build our application with routes // build our application with routes
let app = textsender_api::config::init::app().await; let app = textsender_api::config::init::app().await;