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

@ -2,10 +2,9 @@
name = "hello-world"
version = "0.1.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
workspace = "../"
workspace = ".."
edition = "2018"
[dependencies]
env_logger = "0.5"
actix = "0.7"
actix-web = "^0.7"
env_logger = "0.6"
actix-web = { git="https://github.com/actix/actix-web.git", branch = "1.0" }

View File

@ -1,29 +1,21 @@
extern crate actix;
extern crate actix_web;
extern crate env_logger;
use actix_web::{middleware, web, App, HttpRequest, HttpServer};
use actix_web::{middleware, server, App, HttpRequest};
fn index(_req: &HttpRequest) -> &'static str {
fn index(req: HttpRequest) -> &'static str {
println!("REQ: {:?}", req);
"Hello world!"
}
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
let sys = actix::System::new("hello-world");
server::new(|| {
HttpServer::new(|| {
App::new()
// enable logger
.middleware(middleware::Logger::default())
.resource("/index.html", |r| r.f(|_| "Hello world!"))
.resource("/", |r| r.f(index))
.service(web::resource("/index.html").to(|| "Hello world!"))
.service(web::resource("/").to(index))
})
.bind("127.0.0.1:8080")
.unwrap()
.start();
println!("Started http server: 127.0.0.1:8080");
let _ = sys.run();
.bind("127.0.0.1:8080")?
.run()
}