123 lines
3.4 KiB
Rust
123 lines
3.4 KiB
Rust
#![recursion_limit = "256"]
|
|
|
|
mod admin;
|
|
mod ai_generation_drafts;
|
|
mod ai_tasks;
|
|
mod api_response;
|
|
mod app;
|
|
mod asset_billing;
|
|
mod assets;
|
|
mod auth;
|
|
mod auth_me;
|
|
mod auth_payload;
|
|
mod auth_public_user;
|
|
mod auth_session;
|
|
mod auth_sessions;
|
|
mod big_fish;
|
|
mod big_fish_agent_turn;
|
|
mod big_fish_draft_compiler;
|
|
mod character_animation_assets;
|
|
mod character_visual_assets;
|
|
mod config;
|
|
mod creation_agent_anchor_templates;
|
|
mod creation_agent_chat;
|
|
mod creation_agent_document_input;
|
|
mod creation_agent_llm_turn;
|
|
mod custom_world;
|
|
mod custom_world_agent_entities;
|
|
mod custom_world_agent_turn;
|
|
mod custom_world_ai;
|
|
mod custom_world_asset_prompts;
|
|
mod custom_world_foundation_draft;
|
|
mod custom_world_result_prompts;
|
|
mod custom_world_rpg_draft_prompts;
|
|
mod error_middleware;
|
|
mod health;
|
|
mod http_error;
|
|
mod llm;
|
|
mod llm_model_routing;
|
|
mod login_options;
|
|
mod logout;
|
|
mod logout_all;
|
|
mod match3d;
|
|
mod openai_image_generation;
|
|
mod password_entry;
|
|
mod password_management;
|
|
mod phone_auth;
|
|
mod platform_errors;
|
|
mod profile_identity;
|
|
mod prompt;
|
|
mod puzzle;
|
|
mod puzzle_agent_turn;
|
|
mod refresh_session;
|
|
mod registration_reward;
|
|
mod request_context;
|
|
mod response_headers;
|
|
mod runtime_browse_history;
|
|
mod runtime_chat;
|
|
mod runtime_chat_plain;
|
|
mod runtime_inventory;
|
|
mod runtime_profile;
|
|
mod runtime_save;
|
|
mod runtime_settings;
|
|
mod session_client;
|
|
mod square_hole;
|
|
mod square_hole_agent_turn;
|
|
mod state;
|
|
mod story_battles;
|
|
mod story_sessions;
|
|
mod wechat_auth;
|
|
mod wechat_provider;
|
|
mod work_author;
|
|
|
|
use shared_logging::init_tracing;
|
|
use tokio::net::TcpListener;
|
|
use tokio::runtime::Builder as TokioRuntimeBuilder;
|
|
use tracing::info;
|
|
|
|
use crate::{app::build_router, config::AppConfig, state::AppState};
|
|
|
|
const API_SERVER_STARTUP_STACK_SIZE_BYTES: usize = 32 * 1024 * 1024;
|
|
|
|
fn main() -> Result<(), std::io::Error> {
|
|
// Windows 本地调试下 Axum 路由树和启动恢复链较重,显式放大启动线程栈,避免 debug 构建在进入监听前栈溢出。
|
|
std::thread::Builder::new()
|
|
.name("api-server-bootstrap".to_string())
|
|
.stack_size(API_SERVER_STARTUP_STACK_SIZE_BYTES)
|
|
.spawn(run_api_server_with_runtime)?
|
|
.join()
|
|
.map_err(|_| std::io::Error::other("api-server 启动线程异常退出"))?
|
|
}
|
|
|
|
fn run_api_server_with_runtime() -> Result<(), std::io::Error> {
|
|
TokioRuntimeBuilder::new_multi_thread()
|
|
.enable_all()
|
|
.thread_name("api-server-worker")
|
|
.thread_stack_size(API_SERVER_STARTUP_STACK_SIZE_BYTES)
|
|
.build()?
|
|
.block_on(run_api_server())
|
|
}
|
|
|
|
async fn run_api_server() -> Result<(), std::io::Error> {
|
|
// 运行本地开发与联调时,优先从仓库根目录加载本地变量,避免手工逐项导出 OSS / APIMart 配置。
|
|
let _ = dotenvy::from_filename(".env.secrets.local");
|
|
let _ = dotenvy::from_filename(".env.local");
|
|
let _ = dotenvy::from_filename(".env");
|
|
|
|
// 统一先从配置对象读取监听地址,避免后续把环境变量读取散落到入口和路由层。
|
|
let config = AppConfig::from_env();
|
|
init_tracing(&config.log_filter)?;
|
|
|
|
let bind_address = config.bind_socket_addr();
|
|
let listener = TcpListener::bind(bind_address).await?;
|
|
|
|
let state = AppState::try_restore_auth_store_from_spacetime(config)
|
|
.await
|
|
.map_err(|error| std::io::Error::other(format!("初始化应用状态失败:{error}")))?;
|
|
let router = build_router(state);
|
|
|
|
info!(%bind_address, "api-server 已完成 tracing 初始化并开始监听");
|
|
|
|
axum::serve(listener, router).await
|
|
}
|