Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider an after_start hook of some kind #63

Open
steveklabnik opened this issue Oct 16, 2017 · 2 comments
Open

Consider an after_start hook of some kind #63

steveklabnik opened this issue Oct 16, 2017 · 2 comments

Comments

@steveklabnik
Copy link
Owner

We only have the log crate because we want to print out that the server is starting; we only print out the server is starting because there's no way to customize this kind of thing. The Node api we're emulating does, however.

It might look something like this:

#[macro_use]
extern crate log;
extern crate env_logger;

extern crate simple_server;

use simple_server::Server;

fn main() {
    env_logger::init().unwrap();

    let host = "127.0.0.1";
    let port = "7878";

    let server = Server::new(|request, mut response| {
        info!("Request received. {} {}", request.method(), request.uri());
        Ok(response.body("Hello Rust!".as_bytes())?)
    });

    server.listen(host, port, || {
        info!("Server started on {}:{}", host, port);
    });
}

Thoughts?

@ashleygwilliams
Copy link
Collaborator

haha when we made the original interface i had argued for this as its how the node works. i'm into it, obvi ;)

@steveklabnik
Copy link
Owner Author

Gonna punt this to a 0.5, but I do want to change this interface. There's enough in 0.4 that I'd rather keep the main interface the same for now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants