Pepguy commited on
Commit
9c8dea2
·
verified ·
1 Parent(s): 9820279

Create main.rs

Browse files
Files changed (1) hide show
  1. main.rs +22 -0
main.rs ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use axum::{routing::get, Router};
2
+ use std::net::SocketAddr;
3
+
4
+ #[tokio::main]
5
+ async fn main() {
6
+ // Build our application with a single route
7
+ let app = Router::new()
8
+ .route("/", get(|| async { "Rust is running at Warp Speed on Hugging Face!" }))
9
+ .route("/health", get(|| async { "OK" }));
10
+
11
+ // HF Spaces default port is 7860
12
+ let port = std::env::var("PORT")
13
+ .unwrap_or_else(|_| "7860".to_string())
14
+ .parse::<u16>()
15
+ .unwrap();
16
+
17
+ let addr = SocketAddr::from(([0, 0, 0, 0], port));
18
+ println!("🚀 Server started on {}", addr);
19
+
20
+ let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
21
+ axum::serve(listener, app).await.unwrap();
22
+ }