Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3769712
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/http_server.rs b/src/http_server.rs
index 1b1a081..08b975e 100644
--- a/src/http_server.rs
+++ b/src/http_server.rs
@@ -1,81 +1,80 @@
/* -------------------------------------------------------------
Servers log microservice
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Project: Nasqueron
Created: 2016-11-10
License: BSD-2-Clause
------------------------------------------------------------- */
use iron::prelude::*;
use router::Router;
use std::env;
/* -------------------------------------------------------------
HTTP server
Spawns a HTTP server listens to $BIND environment variable
or by default to *:3000.
The server is based on the Iron framework.
Controller logic is defined in the web_handlers module.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/// Prepares an Iron handler.
fn initialize_handler() -> Router {
- return router!(
+ router!(
index: get "/" => ::web_handlers::get,
status: get "/status" => ::web_handlers::alive
- );
+ )
}
/// Gets the address the HTTP server should bind to.
fn get_bind_address() -> String {
- return env::var("BIND").unwrap_or("0.0.0.0:3000".to_string());
+ env::var("BIND").unwrap_or("0.0.0.0:3000".to_string())
}
/// Runs an HTTP server.
pub fn run() {
let listen = get_bind_address();
info!("Starting HTTP server");
info!("Listen to http://{}", listen);
let _server = Iron::new(initialize_handler()).http(&*listen);
- match _server {
- Err(err) => error!("{}", err),
- Ok(_) => {}
+ if let Err(err) = _server {
+ error!("{}", err)
}
}
/* -------------------------------------------------------------
Tests
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#[cfg(test)]
mod tests {
extern crate iron_test;
use super::get_bind_address;
use super::initialize_handler;
use iron::Headers;
use iron_test::request;
use iron_test::response::extract_body_to_bytes;
#[test]
fn get_bind_address_returns_expected_default_value() {
assert_eq!("0.0.0.0:3000", get_bind_address());
}
#[test]
fn test_router() {
let response = request::get("http://localhost:3000/status",
Headers::new(),
&initialize_handler());
let result = extract_body_to_bytes(response.unwrap());
assert_eq!(result, b"ALIVE");
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 16:37 (22 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260567
Default Alt Text
(2 KB)
Attached To
Mode
rSERVERSLOG Servers log microservice
Attached
Detach File
Event Timeline
Log In to Comment