mirror of
https://github.com/actix/examples
synced 2025-06-28 09:50:36 +02:00
port more examples
This commit is contained in:
@ -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" }
|
||||
|
@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user