add WEB_PORT

This commit is contained in:
2026-04-17 14:20:43 +03:00
parent bb371e1b71
commit fe13a5e3a7
4 changed files with 331 additions and 109 deletions

View File

@@ -18,6 +18,8 @@ pub struct Config {
pub template_composition: String,
pub template_output_module: String,
pub template_output_ext: String,
//web_serwer
pub web_port: u16,
}
impl Config {
@@ -42,6 +44,10 @@ impl Config {
.context("TEMPLATE_OUTPUT_MODULE not set")?,
template_output_ext: env::var("TEMPLATE_OUTPUT_EXT")
.context("TEMPLATE_OUTPUT_EXT not set")?,
web_port: env::var("WEB_PORT")
.unwrap_or_else(|_| "3000".to_string())
.parse()
.context("Invalid WEB_PORT")?,
})
}
}
}

View File

@@ -11,8 +11,8 @@ use serde::Serialize;
use std::net::SocketAddr;
use std::sync::Arc;
use tokio::sync::Mutex;
use tower_http::trace::TraceLayer;
use tower_http::services::ServeDir;
use tower_http::trace::TraceLayer;
#[derive(Clone)]
pub struct AppState {
@@ -88,7 +88,9 @@ impl JobInfo {
}
}
// web.rs - функция run_web_server
pub async fn run_web_server(config: Config) -> anyhow::Result<()> {
let web_port = config.web_port; // Берём порт из конфига
let state = AppState {
config,
last_generation: Arc::new(Mutex::new(None)),
@@ -106,7 +108,7 @@ pub async fn run_web_server(config: Config) -> anyhow::Result<()> {
.layer(TraceLayer::new_for_http())
.with_state(state);
let addr: SocketAddr = "0.0.0.0:3000".parse()?;
let addr: SocketAddr = format!("0.0.0.0:{}", web_port).parse()?;
log::info!("Web server listening on http://{}", addr);
let listener = tokio::net::TcpListener::bind(addr).await?;
@@ -114,7 +116,6 @@ pub async fn run_web_server(config: Config) -> anyhow::Result<()> {
Ok(())
}
// Остальные обработчики остаются без изменений...
async fn index_page() -> Html<&'static str> {
Html(include_str!("static/index.html"))
}