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