Skip to content

Commit

Permalink
update cors middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
fankaiLiu committed Mar 21, 2024
1 parent 074ed44 commit 442e572
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "salvo-cli"
version = "0.1.46"
version = "0.1.47"
edition = "2021"
authors = ["Fankai Liu liufankai137@outlook.com","mrxiaozhuox mrxzx.info@gmail.com"]
keywords = ["salvo", "cli","template"]
Expand Down
6 changes: 3 additions & 3 deletions src/template/src/main_template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::db::init_db_conn;
{{/if}}
use tokio::signal;
use tracing::info;
use crate::middleware::handle_404::handle_404;
use crate::middleware::{handle_404::handle_404,cors::cors_middleware};
use crate::routers::router;
use config::{CERT_KEY, CFG};
use salvo::server::ServerHandle;
Expand Down Expand Up @@ -69,10 +69,10 @@ async fn main() {
{{/if}}
let router = router();
let service: Service = router.into();
let service = service.catcher(Catcher::default().hoop(handle_404));
let service = service.catcher(Catcher::default().hoop(handle_404));//.hoop(_cors_handler).hoop(handle_404));
println!("🌪️ {} {{is_starting}} ", &CFG.server.name);
println!("🔄 {{listen_on}} {}", &CFG.server.address);

let _cors_handler = cors_middleware();
match CFG.server.ssl {
true => {
println!(
Expand Down
5 changes: 1 addition & 4 deletions src/template/src/routers/mod.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#if need_db_conn}}
{{#if is_web_site}}
use crate::middleware::{cors::cors_middleware, jwt::jwt_middleware};
use crate::middleware::jwt::jwt_middleware;
use salvo::{
prelude::{CatchPanic, Logger, OpenApi, SwaggerUi},
Router,
Expand All @@ -23,8 +23,6 @@ pub fn router() -> Router {
Router::with_path("/api/login").post(post_login),
];

let _cors_handler = cors_middleware();

let mut need_auth_routers = vec![
Router::with_path("users")
.get(user_list_page),
Expand All @@ -39,7 +37,6 @@ pub fn router() -> Router {
let static_routers = static_routers::create_static_routers();
no_auth_routers.extend(static_routers);
let router = Router::new()
//.hoop(_cors_handler)
.hoop(Logger::new())
.hoop(CatchPanic::new())
.get(hello)
Expand Down

0 comments on commit 442e572

Please sign in to comment.