From c7543e722867ecbb6e4007a801bd7e5e2858a5ed Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 22 Aug 2018 11:36:56 -0700 Subject: [PATCH] add Server::configure helper --- src/server.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/server.rs b/src/server.rs index c3ba427a..6f129ac9 100644 --- a/src/server.rs +++ b/src/server.rs @@ -135,6 +135,38 @@ impl Server { self } + /// Run external configuration as part of the server building + /// process + /// + /// This function is useful for moving parts of configuration to a + /// different module or event library. + /// + /// ```rust + /// # extern crate actix_web; + /// use actix_web::{fs, middleware, App, HttpResponse}; + /// + /// // this function could be located in different module + /// fn config(app: App) -> App { + /// app.resource("/test", |r| { + /// r.get().f(|_| HttpResponse::Ok()); + /// r.head().f(|_| HttpResponse::MethodNotAllowed()); + /// }) + /// } + /// + /// fn main() { + /// let app = App::new() + /// .middleware(middleware::Logger::default()) + /// .configure(config) // <- register resources + /// .handler("/static", fs::StaticFiles::new(".").unwrap()); + /// } + /// ``` + pub fn configure(self, cfg: F) -> Server + where + F: Fn(Server) -> Server, + { + cfg(self) + } + /// Add new service to server pub fn bind(mut self, addr: U, srv: T) -> io::Result where