1
0
mirror of https://github.com/actix/examples synced 2025-06-28 09:50:36 +02:00

restructure folders

This commit is contained in:
Rob Ede
2022-02-18 02:01:48 +00:00
parent 4d8573c3fe
commit cc3d356209
201 changed files with 52 additions and 49 deletions

View File

@ -1,2 +0,0 @@
# Auto detect text files and perform LF normalization
* text=auto

View File

@ -4,6 +4,7 @@ version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = "4.0.0-rc.1"
actix-web = "4.0.0-rc.3"
actix-files = "0.6.0-beta.15"
env_logger = "0.9.0"
log = "0.4"

View File

@ -1,15 +1,14 @@
use actix_files::Files;
use actix_web::{middleware, App, HttpServer};
use actix_web::{middleware::Logger, App, HttpServer};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
log::info!("starting HTTP server at http://localhost:8080");
HttpServer::new(|| {
App::new()
// Enable the logger.
.wrap(middleware::Logger::default())
// 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.
@ -17,6 +16,8 @@ async fn main() -> std::io::Result<()> {
// 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"))
// Enable the logger.
.wrap(Logger::default())
})
.bind(("127.0.0.1", 8080))?
.run()