1 extern crate actix_web
;
5 use listenfd
::ListenFd
;
7 use actix_web
::{web
, middleware
, App
, HttpServer
, HttpResponse
, Responder
, Result
, web
::Query
};
9 use serde
::{Deserialize}
;
12 #[template(path = "main.html")]
13 struct MainTemplate
<'a
> {
17 #[derive(Deserialize)]
22 fn main_page(query
: Query
<Request
>) -> Result
<HttpResponse
> {
26 None
=> "Marc, roule un pet'!"
29 let hello
= MainTemplate
{ sentence
: m
};
31 let s
= hello
.render().unwrap();
32 Ok(HttpResponse
::Ok().content_type("text/html").body(s
))
35 fn main() -> std
::io
::Result
<()> {
36 let mut listenfd
= ListenFd
::from_env();
41 .wrap(middleware
::Compress
::default())
42 .wrap(middleware
::Logger
::default())
43 .service(web
::resource("/").to(main_page
))
44 .service(fs
::Files
::new("/static", "static").show_files_listing())
49 if let Some(l
) = listenfd
.take_tcp_listener(0).unwrap() {
50 server
.listen(l
).unwrap()
52 server
.bind("0.0.0.0:8082").unwrap()