1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00
examples/unix-socket/src/main.rs
Matt Palmer 324c0d4f53
Correct startup log message for unix-server
I was momentarily confused about where the example was actually listening.
2024-04-10 11:57:05 +10:00

31 lines
873 B
Rust

use actix_web::{middleware, web, App, HttpRequest, HttpServer};
async fn index(_req: HttpRequest) -> &'static str {
"Hello world!"
}
#[actix_web::main]
#[cfg(unix)]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
log::info!("starting HTTP server at unix:/tmp/actix-uds.socket");
HttpServer::new(|| {
App::new()
// enable logger - always register Actix Web Logger middleware last
.wrap(middleware::Logger::default())
.service(web::resource("/index.html").route(web::get().to(|| async { "Hello world!" })))
.service(web::resource("/").to(index))
})
.bind_uds("/tmp/actix-uds.socket")?
.run()
.await
}
#[cfg(not(unix))]
fn main() -> std::io::Result<()> {
log::info!("Example only runs on UNIX");
Ok(())
}