Skip to content

Instantly share code, notes, and snippets.

@brianloveswords
Last active September 29, 2015 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianloveswords/e157b32e5c41c12b83dd to your computer and use it in GitHub Desktop.
Save brianloveswords/e157b32e5c41c12b83dd to your computer and use it in GitHub Desktop.
extern crate iron;
extern crate router;
use iron::status;
use iron::{Iron, Request, Response};
use std::io::Read;
use router::Router;
fn main() {
let mut router = Router::new();
// This if this handler receives two requests from GitHub the
// entire Iron server will never be able to handle a request
// again.
router.post("/hookshot", move |req: &mut Request| {
println!("request received, processing");
println!("loading body into string");
let mut payload = String::new();
if req.body.read_to_string(&mut payload).is_err() {
println!("could not read body into string");
return Ok(Response::with((status::InternalServerError)))
}
println!("responding");
Ok(Response::with((status::Ok, "pong")))
});
println!("listening on port 4200");
Iron::new(router).http("0.0.0.0:4200").unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment