2020-05-18 01:28:47 +03:00
|
|
|
use actix_files::Files;
|
2022-02-18 02:01:48 +00:00
|
|
|
use actix_web::{middleware::Logger, App, HttpServer};
|
2018-04-16 16:38:29 -04:00
|
|
|
|
2020-09-12 16:49:45 +01:00
|
|
|
#[actix_web::main]
|
2019-12-07 23:59:24 +06:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2022-02-18 02:01:48 +00:00
|
|
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
|
|
|
|
|
|
|
log::info!("starting HTTP server at http://localhost:8080");
|
2018-04-16 16:38:29 -04:00
|
|
|
|
2019-03-09 22:38:15 -08:00
|
|
|
HttpServer::new(|| {
|
2018-05-20 21:03:29 -07:00
|
|
|
App::new()
|
2020-05-18 01:28:47 +03:00
|
|
|
// We allow the visitor to see an index of the images at `/images`.
|
|
|
|
.service(Files::new("/images", "static/images/").show_files_listing())
|
|
|
|
// Serve a tree of static files at the web root and specify the index file.
|
|
|
|
// Note that the root path should always be defined as the last item. The paths are
|
|
|
|
// resolved in the order they are defined. If this would be placed before the `/images`
|
|
|
|
// path then the service for the static images would never be reached.
|
|
|
|
.service(Files::new("/", "./static/root/").index_file("index.html"))
|
2022-02-18 02:01:48 +00:00
|
|
|
// Enable the logger.
|
|
|
|
.wrap(Logger::default())
|
2019-03-09 18:03:09 -08:00
|
|
|
})
|
2022-02-17 20:22:36 +00:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2019-12-25 20:48:33 +04:00
|
|
|
.run()
|
2019-12-07 23:59:24 +06:00
|
|
|
.await
|
2018-04-16 16:38:29 -04:00
|
|
|
}
|