update
This commit is contained in:
@ -18,10 +18,11 @@ use std::sync::Arc;
|
||||
async fn main() {
|
||||
dotenvy::dotenv().ok();
|
||||
let db_url = env::var("DATABASE_URL").expect(".env 文件中没有设置 DATABASE_URL");
|
||||
let upload_path = env::var("UPLOAD_PATH").expect(".env 文件中没有设置 UPLOAD_PATH");
|
||||
|
||||
let db_conn = Database::connect(&db_url).await.expect("数据库链接失败");
|
||||
|
||||
let app_state = AppState { db_conn };
|
||||
let app_state = AppState { db_conn, upload_path };
|
||||
|
||||
let app = routes::create_routes(Arc::new(app_state));
|
||||
Server::bind(&"0.0.0.0:3000".parse().unwrap())
|
||||
|
@ -3,12 +3,14 @@ use crate::state::app::AppState;
|
||||
use axum::routing::{get, IntoMakeService};
|
||||
use axum::{Router, ServiceExt};
|
||||
use std::sync::Arc;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
pub fn create_routes(app_state: Arc<AppState>) -> IntoMakeService<Router> {
|
||||
Router::new()
|
||||
.nest(
|
||||
"/api",
|
||||
Router::new()
|
||||
.nest_service("/uploads",ServeDir::new(&app_state.upload_path))
|
||||
.nest("/article", Router::new().route("/list", get(article_list)))
|
||||
.nest(
|
||||
"/pc",
|
||||
|
@ -2,4 +2,5 @@ use sea_orm::DatabaseConnection;
|
||||
|
||||
pub struct AppState {
|
||||
pub db_conn: DatabaseConnection,
|
||||
pub upload_path: String,
|
||||
}
|
||||
|
Reference in New Issue
Block a user