1
0
mirror of https://github.com/actix/examples synced 2025-02-12 21:45:32 +01:00

31 lines
873 B
Rust
Raw Normal View History

2019-07-18 18:03:19 +06:00
use actix_web::{middleware, web, App, HttpRequest, HttpServer};
2019-12-07 23:59:24 +06:00
async fn index(_req: HttpRequest) -> &'static str {
"Hello world!"
}
2020-09-12 16:49:45 +01:00
#[actix_web::main]
2019-12-07 23:59:24 +06:00
#[cfg(unix)]
async fn main() -> std::io::Result<()> {
2023-03-14 03:11:49 +00:00
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
log::info!("starting HTTP server at unix:/tmp/actix-uds.socket");
2019-07-18 18:03:19 +06:00
HttpServer::new(|| {
2018-05-08 11:08:43 -07:00
App::new()
2022-02-06 08:13:24 +00:00
// enable logger - always register Actix Web Logger middleware last
2019-07-18 18:03:19 +06:00
.wrap(middleware::Logger::default())
2022-02-18 02:44:02 +00:00
.service(web::resource("/index.html").route(web::get().to(|| async { "Hello world!" })))
2019-07-18 18:03:19 +06:00
.service(web::resource("/").to(index))
2019-03-09 18:03:09 -08:00
})
2019-07-18 18:03:19 +06:00
.bind_uds("/tmp/actix-uds.socket")?
2019-12-25 20:48:33 +04:00
.run()
2019-12-07 23:59:24 +06:00
.await
}
#[cfg(not(unix))]
fn main() -> std::io::Result<()> {
2023-03-14 03:11:49 +00:00
log::info!("Example only runs on UNIX");
2019-12-07 23:59:24 +06:00
Ok(())
}