mirror of
https://github.com/actix/examples
synced 2025-06-28 09:50:36 +02:00
restructure folders
This commit is contained in:
2
basics/static_index/.gitattributes
vendored
2
basics/static_index/.gitattributes
vendored
@ -1,2 +0,0 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
@ -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"
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user