mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 18:44:35 +01:00
add README examples/template_tera
This commit is contained in:
parent
12345004dd
commit
8e580ef7b9
@ -5,6 +5,6 @@ authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
env_logger = "0.4"
|
env_logger = "0.4"
|
||||||
actix = "^0.3.1"
|
actix = "^0.3.5"
|
||||||
actix-web = { git = "https://github.com/actix/actix-web.git" }
|
actix-web = { git = "https://github.com/actix/actix-web", features=["signal"] }
|
||||||
tera = "*"
|
tera = "*"
|
||||||
|
17
examples/template_tera/README.md
Normal file
17
examples/template_tera/README.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# template_tera
|
||||||
|
|
||||||
|
Minimal example of using the template [tera](https://github.com/Keats/tera) that displays a form.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### server
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd actix-web/examples/template_tera
|
||||||
|
cargo run (or ``cargo watch -x run``)
|
||||||
|
# Started http server: 127.0.0.1:8080
|
||||||
|
```
|
||||||
|
|
||||||
|
### web client
|
||||||
|
|
||||||
|
- [http://localhost:8080](http://localhost:8080)
|
@ -4,6 +4,8 @@ extern crate env_logger;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tera;
|
extern crate tera;
|
||||||
use actix_web::*;
|
use actix_web::*;
|
||||||
|
use actix::Arbiter;
|
||||||
|
use actix::actors::signal::{ProcessSignals, Subscribe};
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
template: tera::Tera, // <- store tera template in application state
|
template: tera::Tera, // <- store tera template in application state
|
||||||
@ -30,7 +32,7 @@ fn main() {
|
|||||||
let _ = env_logger::init();
|
let _ = env_logger::init();
|
||||||
let sys = actix::System::new("tera-example");
|
let sys = actix::System::new("tera-example");
|
||||||
|
|
||||||
HttpServer::new(|| {
|
let addr = HttpServer::new(|| {
|
||||||
let tera = compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*"));
|
let tera = compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*"));
|
||||||
|
|
||||||
Application::with_state(State{template: tera})
|
Application::with_state(State{template: tera})
|
||||||
@ -40,6 +42,10 @@ fn main() {
|
|||||||
.bind("127.0.0.1:8080").unwrap()
|
.bind("127.0.0.1:8080").unwrap()
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
|
// Subscribe to unix signals
|
||||||
|
let signals = Arbiter::system_registry().get::<ProcessSignals>();
|
||||||
|
signals.send(Subscribe(addr.subscriber()));
|
||||||
|
|
||||||
println!("Started http server: 127.0.0.1:8080");
|
println!("Started http server: 127.0.0.1:8080");
|
||||||
let _ = sys.run();
|
let _ = sys.run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user