<commit_before>extern crate serialize;
extern crate nickel;
extern crate http;

use nickel::{ Nickel, Request, Response };
use std::io::net::ip::Ipv4Addr;

fn main() {

    let mut server = Nickel::new();

    fn bar_handler (_request: &Request, response: &mut Response) {
        response.send("This is the /bar handler");
    }

    // go to http://localhost:6767/bar to see this route in action
    server.get("/bar", bar_handler);

    fn foo_handler (_request: &Request, response: &mut Response) {
        response.send("This is the /foo handler");
    }

    // go to http://localhost:6767/foo to see this route in action
    server.get("/foo", foo_handler);

    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}<commit_msg>fix(example): return proper 404 for unmatched routes<commit_after>extern crate serialize;
extern crate nickel;
extern crate http;

use http::status::{ NotFound };
use nickel::{ Nickel, Request, Response, ErrorWithStatusCode, Action, NickelError, IntoMiddleware };
use std::io::net::ip::Ipv4Addr;

fn main() {

    let mut server = Nickel::new();

    fn bar_handler (_request: &Request, response: &mut Response) {
        response.send("This is the /bar handler");
    }

    // go to http://localhost:6767/bar to see this route in action
    server.get("/bar", bar_handler);

    fn foo_handler (_request: &Request, response: &mut Response) {
        response.send("This is the /foo handler");
    }

    // go to http://localhost:6767/foo to see this route in action
    server.get("/foo", foo_handler);

    //middleware to catch all non matched routes
    fn catch_all (_request: &Request, _response: &mut Response) -> Result<Action, NickelError> {
        Err(NickelError::new("File Not Found", ErrorWithStatusCode(NotFound)))
    }

    // middleware is optional and can be registered with `utilize`
    server.utilize(IntoMiddleware::from_fn(catch_all));

    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}
{'fraction_non_alphanumeric': 0.13446676970633695, 'fraction_numerical': 0.02215352910870685, 'mean_word_length': 3.6795180722891567, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4110275', 'n_tokens_mistral': 628, 'n_tokens_neox': 581, 'n_words': 189}