Add actix-web
This commit is contained in:
parent
04802434fd
commit
6bbb421167
3 changed files with 1235 additions and 2 deletions
1218
Cargo.lock
generated
Normal file
1218
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
actix-web = "4"
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -1,3 +1,17 @@
|
||||||
fn main() {
|
use std::env;
|
||||||
println!("Hello, world!");
|
|
||||||
|
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
|
||||||
|
|
||||||
|
async fn pong() -> impl Responder {
|
||||||
|
HttpResponse::Ok().body("PONG")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
let port: u16 = env::var("PORT").map_or(8080, |p| p.parse::<u16>().unwrap_or(8080));
|
||||||
|
|
||||||
|
HttpServer::new(|| App::new().route("/ping", web::get().to(pong)))
|
||||||
|
.bind(("0.0.0.0", port))?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue