현재 시간을 출력하는 페이지 작성
This commit is contained in:
89
src/main.rs
89
src/main.rs
@@ -1,3 +1,88 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use tokio::signal;
|
||||
use axum::Router;
|
||||
use axum::routing::get;
|
||||
// use axum::response::Html;
|
||||
use chrono::Local;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
println!("listening on {}", listener.local_addr().unwrap());
|
||||
axum::serve(listener, router())
|
||||
.with_graceful_shutdown(shutdown_signal())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
async fn shutdown_signal() {
|
||||
let ctrl_c = async {
|
||||
signal::ctrl_c()
|
||||
.await
|
||||
.expect("failed to listen for ctrl-c event");
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
let terminate = async {
|
||||
signal::unix::signal(signal::unix::SignalKind::terminate())
|
||||
.expect("failed to install signal handler")
|
||||
.recv()
|
||||
.await;
|
||||
};
|
||||
|
||||
#[cfg(not(unix))]
|
||||
let terminate = std::future::pending::<()>();
|
||||
|
||||
tokio::select! {
|
||||
_ = ctrl_c => {},
|
||||
_ = terminate => {},
|
||||
};
|
||||
}
|
||||
|
||||
pub fn router() -> Router {
|
||||
Router::new()
|
||||
.route("/", get(root))
|
||||
}
|
||||
|
||||
async fn root() -> axum::response::Html<String> {
|
||||
|
||||
let current_time = Local::now().format("%Y-%m-%d %H:%M:%S").to_string();
|
||||
axum::response::Html(format!("<h1>Current Time: {}</h1>", current_time))
|
||||
}
|
||||
|
||||
// pub fn router() -> Router {
|
||||
// Router::new()
|
||||
// .route("/", get(root))
|
||||
// .nest("/api", nest_router())
|
||||
// }
|
||||
|
||||
// async fn root() -> axum::response::Html<String> {
|
||||
// axum::response::Html("<h1>root</h1>".to_string())
|
||||
// }
|
||||
|
||||
// pub fn nest_router() -> Router {
|
||||
// Router::new()
|
||||
// .route("/", get(api))
|
||||
// .route("/test", get(handler))
|
||||
// }
|
||||
|
||||
// async fn api() -> axum::response::Html<String> {
|
||||
// axum::response::Html("<h1>api</h1>".to_string())
|
||||
// }
|
||||
|
||||
// async fn handler() -> Html<String> {
|
||||
|
||||
// let env_0 = std::env::var("RWT_ENV_VAR_0").unwrap_or_else(|_| "FALLBACK_0".to_string());
|
||||
// let env_1 = std::env::var("RWT_ENV_VAR_1").unwrap_or_else(|_| "FALLBACK_1".to_string());
|
||||
// let env_2 = std::env::var("RWT_ENV_VAR_2").unwrap_or_else(|_| "FALLBACK_2".to_string());
|
||||
|
||||
// let combined_env = format!("RWT_ENV_VAR_0: {}<br> RWT_ENV_VAR_1: {}<br> RWT_ENV_VAR_2: {}<br>", env_0, env_1, env_2);
|
||||
// Html(format!("<h1>{}</h1>", combined_env))
|
||||
// }
|
||||
|
||||
// async fn add(axum::extract::Path((a, b)): axum::extract::Path<(i32, i32)>) -> Html<String> {
|
||||
// let sum = a + b;
|
||||
// Html(format!("<h1>Sum: {}</h1>", sum))
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user