不在上传数据库
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
/dist
|
/dist
|
||||||
|
*.sqlite
|
||||||
BIN
data.sqlite
BIN
data.sqlite
Binary file not shown.
@ -2,12 +2,13 @@ use include_dir::include_dir;
|
|||||||
|
|
||||||
pub const PROJECT_DIR: include_dir::Dir = include_dir!("./template/dist"); //将前端硬编码到项目
|
pub const PROJECT_DIR: include_dir::Dir = include_dir!("./template/dist"); //将前端硬编码到项目
|
||||||
|
|
||||||
pub const DIST_DIR: &str = "./dist"; //前端释放目录
|
// pub const DIST_DIR: &str = "./dist"; //前端释放目录
|
||||||
// pub const DIST_DIR: &str = "./template/dist"; //前端释放目录
|
pub const DIST_DIR: &str = "./template/dist"; //前端释放目录
|
||||||
|
|
||||||
pub const DATABASE: &str = "./data.sqlite"; //保存数据的目录
|
pub const DATABASE: &str = "./data.sqlite"; //保存数据的目录
|
||||||
|
|
||||||
pub const PORT: u16 = 80;
|
pub const PORT: u16 = 80;
|
||||||
|
pub const BROWER_OPEN: bool = true;
|
||||||
|
|
||||||
pub mod sql {
|
pub mod sql {
|
||||||
pub const CREATE_TABLE_TASKS: &str = "
|
pub const CREATE_TABLE_TASKS: &str = "
|
||||||
|
|||||||
@ -49,7 +49,7 @@ pub async fn reg(
|
|||||||
Common::success("注册成功".to_string())
|
Common::success("注册成功".to_string())
|
||||||
}
|
}
|
||||||
Err(e) => match e {
|
Err(e) => match e {
|
||||||
sqlx::Error::Database(_) => Common::failure("该账号已注册".to_string()),
|
// sqlx::Error::Database(_) => Common::failure("该账号已注册".to_string()),
|
||||||
_ => Common::failure(e.to_string()),
|
_ => Common::failure(e.to_string()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -85,11 +85,11 @@ pub async fn login(
|
|||||||
pub async fn logout(mut auth_session: AuthSession, username: String) -> impl IntoResponse {
|
pub async fn logout(mut auth_session: AuthSession, username: String) -> impl IntoResponse {
|
||||||
match auth_session.logout().await {
|
match auth_session.logout().await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("用户:[{}]退出登陆", username);
|
info!("用户:[{}]退出登陆", auth_session.user.unwrap().username);
|
||||||
Common::success("退出登陆成功".to_string())
|
Common::success("退出登陆成功".to_string())
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("用户:[{}]退出登陆失败:{:?}", username, e);
|
error!("用户:[{}]退出登陆失败:{:?}", auth_session.user.unwrap().username, e);
|
||||||
Common::success(format!("退出登陆失败:{:?}", e))
|
Common::success(format!("退出登陆失败:{:?}", e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,8 +26,8 @@ use constant::DIST_DIR;
|
|||||||
use constant::PORT;
|
use constant::PORT;
|
||||||
use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
use crate::constant::DATABASE;
|
|
||||||
use crate::constant::PROJECT_DIR;
|
use crate::constant::PROJECT_DIR;
|
||||||
|
use crate::constant::{BROWER_OPEN, DATABASE};
|
||||||
use crate::routers::api_routes_init;
|
use crate::routers::api_routes_init;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -87,13 +87,13 @@ async fn main() {
|
|||||||
.with_state(db)
|
.with_state(db)
|
||||||
.layer(auth_layer)
|
.layer(auth_layer)
|
||||||
.layer(TraceLayer::new_for_http());
|
.layer(TraceLayer::new_for_http());
|
||||||
// .route("/test", get())// 测试接口
|
|
||||||
//.layer(middleware::from_fn(logging_middleware));
|
//.layer(middleware::from_fn(logging_middleware));
|
||||||
|
|
||||||
let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{PORT}"))
|
let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{PORT}"))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
info!("成功启用服务:http://0.0.0.0:{PORT}");
|
info!("成功启用服务:http://0.0.0.0:{PORT}");
|
||||||
|
if BROWER_OPEN {
|
||||||
match webbrowser::open(&format!("http://127.0.0.1:{PORT}")) {
|
match webbrowser::open(&format!("http://127.0.0.1:{PORT}")) {
|
||||||
Ok(_) => info!(
|
Ok(_) => info!(
|
||||||
"成功打开浏览器并访问: {}",
|
"成功打开浏览器并访问: {}",
|
||||||
@ -101,6 +101,7 @@ async fn main() {
|
|||||||
),
|
),
|
||||||
Err(e) => error!("无法打开浏览器: {}", e),
|
Err(e) => error!("无法打开浏览器: {}", e),
|
||||||
};
|
};
|
||||||
|
}
|
||||||
axum::serve(listener, app)
|
axum::serve(listener, app)
|
||||||
.with_graceful_shutdown(shutdown_signal(deletion_task.abort_handle()))
|
.with_graceful_shutdown(shutdown_signal(deletion_task.abort_handle()))
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user