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

port more examples

This commit is contained in:
Nikolay Kim
2019-03-09 22:38:15 -08:00
parent b6929b47b1
commit 52c12f264a
9 changed files with 61 additions and 109 deletions

View File

@ -1,31 +1,19 @@
extern crate actix;
extern crate actix_web;
extern crate env_logger;
use actix_files as fs;
use actix_web::{middleware, App, HttpServer};
use actix_web::{fs, middleware, server, App};
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
::std::env::set_var("RUST_BACKTRACE", "1");
fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
let sys = actix::System::new("static_index");
server::new(|| {
HttpServer::new(|| {
App::new()
// enable logger
.middleware(middleware::Logger::default())
.handler(
"/",
fs::StaticFiles::new("./static/")
.unwrap()
.index_file("index.html"),
.service(
// static files
fs::Files::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();
.bind("127.0.0.1:8080")?
.run()
}