Last active
September 29, 2015 04:32
-
-
Save brianloveswords/e157b32e5c41c12b83dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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