lingdu1234 / axum_admin

axum admin rust vue
https://314.iu1314.top/
218 stars 37 forks source link

api_prefix 怎么设置 #4

Closed sunnyboy00 closed 1 year ago

sunnyboy00 commented 1 year ago

let app = Router::new() .nest(&CFG.server.api_prefix, apps::api()) // "/" 与所有路由冲突

lingdu1234 commented 1 year ago

一般设置为API 版本号,或者随意一个名称吧,因为我这个有静态文件,/这个路由被静态文件暂用了,区分开就可以

lingdu1234 commented 1 year ago

我重新更新下 模板文件,太久没有更新,模板里面好多都没有

sunnyboy00 commented 1 year ago

// .nest(&CFG.server.api_prefix, apps::api()) 更改为 .merge(apps::api())

另外就是 加api前缀

pub fn api() -> Router { Router::new() // 文件上传api .nest( &CFG.web.upload_url, get_service(ServeDir::new(&CFG.web.upload_dir)) .handle_error(|error: std::io::Error| async move { (StatusCode::INTERNAL_SERVER_ERROR, for at!("Unhandled internal error: {}", error)) }), ) // 无需授权Api.通用模块 //.nest("/comm", no_auth_api()) .nest("/api/comm", no_auth_api()) // 系统管理模块 // .nest("/system", auth_api()) .nest("/api/system", auth_api()) // 测试模块 //.nest("/test", test_api()) .nest("/api/test", test_api()) }

lingdu1234 commented 1 year ago

我重新更新了 congfig sample 文件 api_prefix 需要前面加 "/" 像 “/api_v1” 这样的