Crates.io | iron_vhosts |
lib.rs | iron_vhosts |
version | 0.5.0 |
source | src |
created_at | 2015-05-05 18:16:15.765412 |
updated_at | 2017-01-19 20:40:08.939749 |
description | An Iron addon to allow requests to be routed based on the host. |
homepage | https://github.com/sbditto85/iron_vhosts |
repository | https://github.com/sbditto85/iron_vhosts |
max_upload_size | |
id | 2034 |
size | 6,447 |
Vhost handler for the Iron web framework.
extern crate iron;
extern crate iron_vhosts;
use iron::prelude::*;
use iron::status;
use iron_vhosts::Vhosts;
fn main () {
//Default handler passed to new
let mut vhosts = Vhosts::new(|_: &mut Request| Ok(Response::with((status::Ok, "vhost"))));
//Add any host specific handlers
vhosts.add_host("localhost", localhost_handler);
vhosts.add_host("media.localhost", media_handler);
fn localhost_handler(_: &mut Request) -> IronResult<Response> {
Ok(Response::with((status::Ok, "localhost")))
}
fn media_handler(_: &mut Request) -> IronResult<Response> {
Ok(Response::with((status::Ok, "media")))
}
Iron::new(vhosts).http("localhost:3000").unwrap();
}
If you're using cargo, just add iron_vhosts to your Cargo.toml
.
[dependencies]
iron_vhosts = "*"