mirror of
https://github.com/actix/examples
synced 2025-06-28 18:00:37 +02:00
Adding first draft of static index example
This commit is contained in:
32
static_index/src/main.rs
Normal file
32
static_index/src/main.rs
Normal file
@ -0,0 +1,32 @@
|
||||
extern crate actix;
|
||||
extern crate actix_web;
|
||||
extern crate env_logger;
|
||||
|
||||
use actix_web::{fs, App, server, middleware};
|
||||
|
||||
fn main() {
|
||||
::std::env::set_var("RUST_LOG", "actix_web=info");
|
||||
::std::env::set_var("RUST_BACKTRACE", "1");
|
||||
env_logger::init();
|
||||
|
||||
let sys = actix::System::new("static_index");
|
||||
|
||||
|
||||
server::new(
|
||||
|| App::new()
|
||||
// enable logger
|
||||
.middleware(middleware::Logger::default())
|
||||
.handler(
|
||||
"/",
|
||||
fs::StaticFiles::new("./static/").index_file("index.html")
|
||||
)
|
||||
)
|
||||
|
||||
.bind("127.0.0.1:8080").expect( "Can not start server on given IP/Port" )
|
||||
.start();
|
||||
|
||||
println!("Started http server: 127.0.0.1:8080");
|
||||
let _ = sys.run();
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user