feat: 更新环境配置和错误处理逻辑
- 更新后端端口号和环境配置,添加Redis支持 - 改进错误处理,添加带消息的未授权和禁止访问错误 - 优化前端登录流程和错误提示 - 更新前端页面标题和欢迎信息 - 清理未使用的代码模块
This commit is contained in:
@ -7,7 +7,7 @@ pub mod models;
|
||||
pub mod services;
|
||||
pub mod routes;
|
||||
pub mod utils;
|
||||
pub mod workflow;
|
||||
//pub mod workflow;
|
||||
|
||||
use axum::Router;
|
||||
use axum::http::{HeaderValue, Method};
|
||||
@ -17,12 +17,12 @@ use axum::middleware;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
// 增强:支持通过 ENV_FILE 指定要加载的环境文件
|
||||
// 增强:支持通过 ENV_FILE 指定要加载的环境文件,并记录实际加载的文件
|
||||
// - ENV_FILE=prod 或 production => .env.prod
|
||||
// - ENV_FILE=dev 或 development => .env
|
||||
// - ENV_FILE=staging => .env.staging
|
||||
// - ENV_FILE=任意字符串 => 视为显式文件名或路径
|
||||
if let Ok(v) = std::env::var("ENV_FILE") {
|
||||
let env_file_used: Option<String> = if let Ok(v) = std::env::var("ENV_FILE") {
|
||||
let filename = match v.trim() {
|
||||
"" => ".env".to_string(),
|
||||
"prod" | "production" => ".env.prod".to_string(),
|
||||
@ -30,10 +30,16 @@ async fn main() -> anyhow::Result<()> {
|
||||
"staging" | "pre" | "preprod" | "pre-production" => ".env.staging".to_string(),
|
||||
other => other.to_string(),
|
||||
};
|
||||
dotenvy::from_filename(&filename).ok();
|
||||
match dotenvy::from_filename_override(&filename) {
|
||||
Ok(_) => Some(filename),
|
||||
Err(_) => Some(format!("{} (not found)", filename)),
|
||||
}
|
||||
} else {
|
||||
dotenvy::dotenv().ok();
|
||||
}
|
||||
match dotenvy::dotenv_override() {
|
||||
Ok(path) => Some(path.to_string_lossy().to_string()),
|
||||
Err(_) => None,
|
||||
}
|
||||
};
|
||||
|
||||
tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init();
|
||||
|
||||
@ -91,7 +97,13 @@ async fn main() -> anyhow::Result<()> {
|
||||
.layer(cors)
|
||||
.layer(middleware::from_fn_with_state(db.clone(), middlewares::logging::request_logger));
|
||||
|
||||
let addr = format!("{}:{}", std::env::var("APP_HOST").unwrap_or("0.0.0.0".into()), std::env::var("APP_PORT").unwrap_or("8080".into()));
|
||||
// 读取并记录最终使用的主机与端口(默认端口改为 9898)
|
||||
let app_host = std::env::var("APP_HOST").unwrap_or("0.0.0.0".into());
|
||||
let app_port = std::env::var("APP_PORT").unwrap_or("9898".into());
|
||||
if let Some(f) = &env_file_used { tracing::info!("env file loaded: {}", f); } else { tracing::info!("env file loaded: <none>"); }
|
||||
tracing::info!("resolved APP_HOST={} APP_PORT={}", app_host, app_port);
|
||||
|
||||
let addr = format!("{}:{}", app_host, app_port);
|
||||
tracing::info!("listening on {}", addr);
|
||||
axum::serve(tokio::net::TcpListener::bind(addr).await?, app).await?;
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user