Skip to content

Consider an after_start hook of some kind #63

Description

@steveklabnik

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?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions