diff --git a/README.md b/README.md index 51f6ce2a..76306ec6 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Some basic benchmarks could be found in this [respository](https://github.com/fa ## Examples -* [Basic](https://github.com/actix/actix-web/tree/master/examples/basic.rs) +* [Basic](https://github.com/actix/actix-web/tree/master/examples/basic/) * [Stateful](https://github.com/actix/actix-web/tree/master/examples/state.rs) * [Mulitpart streams](https://github.com/actix/actix-web/tree/master/examples/multipart/) * [Simple websocket session](https://github.com/actix/actix-web/tree/master/examples/websocket.rs) diff --git a/examples/basic/Cargo.toml b/examples/basic/Cargo.toml new file mode 100644 index 00000000..6bb442e4 --- /dev/null +++ b/examples/basic/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "basic" +version = "0.1.0" +authors = ["Nikolay Kim "] + +[dependencies] +futures = "*" +env_logger = "0.4" +actix = "^0.3.5" +actix-web = { git = "https://github.com/actix/actix-web", features=["signal"] } diff --git a/examples/basic/README.md b/examples/basic/README.md new file mode 100644 index 00000000..45772e91 --- /dev/null +++ b/examples/basic/README.md @@ -0,0 +1,19 @@ +# basic + +## Usage + +### server + +```bash +cd actix-web/examples/basic +cargo run +# Started http server: 127.0.0.1:8080 +``` + +### web client + +- [http://localhost:8080/index.html](http://localhost:8080/index.html) +- [http://localhost:8080/async/bob](http://localhost:8080/async/bob) +- [http://localhost:8080/user/bob/](http://localhost:8080/user/bob/) plain/text download +- [http://localhost:8080/test](http://localhost:8080/test) (return status switch GET or POST or other) +- [http://localhost:8080/static/index.html](http://localhost:8080/static/index.html) \ No newline at end of file diff --git a/examples/basic.rs b/examples/basic/src/main.rs similarity index 90% rename from examples/basic.rs rename to examples/basic/src/main.rs index 7328a5a9..46fe20c6 100644 --- a/examples/basic.rs +++ b/examples/basic/src/main.rs @@ -8,6 +8,8 @@ extern crate futures; use futures::Stream; use actix_web::*; +use actix::Arbiter; +use actix::actors::signal::{ProcessSignals, Subscribe}; use actix_web::middleware::RequestSession; use futures::future::{FutureResult, result}; @@ -57,7 +59,7 @@ fn main() { let _ = env_logger::init(); let sys = actix::System::new("basic-example"); - HttpServer::new( + let addr = HttpServer::new( || Application::new() // enable logger .middleware(middleware::Logger::default()) @@ -82,7 +84,7 @@ fn main() { })) // static files .resource("/static/{tail:.*}", - |r| r.h(fs::StaticFiles::new("tail", "examples/static/", true))) + |r| r.h(fs::StaticFiles::new("tail", "../static/", true))) // redirect .resource("/", |r| r.method(Method::GET).f(|req| { println!("{:?}", req); @@ -94,6 +96,10 @@ fn main() { .bind("0.0.0.0:8080").unwrap() .start(); + // Subscribe to unix signals + let signals = Arbiter::system_registry().get::(); + signals.send(Subscribe(addr.subscriber())); + println!("Starting http server: 127.0.0.1:8080"); let _ = sys.run(); }