|
|
@@ -2,7 +2,7 @@ mod datasource;
|
|
|
mod api;
|
|
|
use std::{collections::HashMap, process::exit, str::FromStr};
|
|
|
|
|
|
-use axum::{extract::State, routing::any};
|
|
|
+use axum::{routing::any};
|
|
|
use datasource::sqlite;
|
|
|
use tokio::sync::Mutex;
|
|
|
use tower_http::cors::{Any, CorsLayer}; // 添加Any和CorsLayer的引用
|
|
|
@@ -129,7 +129,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
} else{None}
|
|
|
};
|
|
|
|
|
|
- let monitor = Counter::new();
|
|
|
+ // let monitor = Counter::new();
|
|
|
|
|
|
use axum::routing::{post,get};
|
|
|
let app = axum::Router::new()
|
|
|
@@ -193,10 +193,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
// .route("/", get(|couter:State<Counter>| async move {"hello".to_string()}))
|
|
|
.route("/", any(|| async {"hello".to_string()}))
|
|
|
// .route("/hello", get(api::example))
|
|
|
- .nest("/monitor", axum::Router::new()
|
|
|
- .route("/show", get(|c:State<Counter>|async move{ axum::Json::from(c.get_counts().await) }))
|
|
|
- .with_state(monitor)
|
|
|
- )
|
|
|
+ // .nest("/monitor", axum::Router::new()
|
|
|
+ // .route("/show", get(|c:State<Counter>|async move{ axum::Json::from(c.get_counts().await) }))
|
|
|
+ // .with_state(monitor)
|
|
|
+ // )
|
|
|
+ .layer(CorsLayer::new()
|
|
|
+ .allow_origin(Any)
|
|
|
+ .allow_methods(Any)
|
|
|
+ .allow_headers(Any))
|
|
|
;
|
|
|
if let (Some(cert),Some(key),Some(ssl)) = (conf.ssl_cert,conf.ssl_key,conf.ssl) {
|
|
|
use axum_server::tls_rustls::RustlsConfig;
|