1
0
mirror of https://github.com/actix/examples synced 2025-06-28 09:50:36 +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

@ -2,11 +2,12 @@
name = "static_index"
version = "0.1.0"
authors = ["Jose Marinez <digeratus@gmail.com>"]
workspace = "../"
workspace = ".."
edition = "2018"
[dependencies]
futures = "0.1"
env_logger = "0.5"
actix = "0.7"
actix-web = "0.7"
actix-web = { git="https://github.com/actix/actix-web.git", branch = "1.0" }
actix-files = { git="https://github.com/actix/actix-web.git", branch = "1.0" }

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()
}