Skip to content

Commit 684d3ca

Browse files
author
Cedric Gatay
authored
Merge pull request #27 from code-troopers/fix/windowsBuild
chore(): Fix windows build target
2 parents f439c09 + a0d1f61 commit 684d3ca

File tree

3 files changed

+55
-23
lines changed

3 files changed

+55
-23
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ matrix:
4747
# # Windows
4848
# - env: TARGET=x86_64-pc-windows-gnu
4949
# Windows
50-
# - env: TARGET=x86_64-pc-windows-gnu
51-
# rust: nightly
50+
- env: TARGET=x86_64-pc-windows-gnu
51+
rust: nightly
5252

5353
# Testing other channels
5454
- env: TARGET=x86_64-unknown-linux-gnu

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ serde_derive = "1.0"
1515
# Each data format lives in its own crate; the sample code below uses JSON
1616
# but you may be using a different one.
1717
serde_json = "1.0"
18-
rocket = "0.3.11"
19-
rocket_codegen = "0.3.11"
18+
hyper = "0.12.0"
19+
futures = "0.1.21"
2020
linked-hash-map = "0.5.1"
2121
lazy_static = "1.0"
22-
clap = "2.0.0"
22+
clap = "2.0.0"

src/lib.rs

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#![feature(plugin, extern_prelude)]
2-
#![plugin(rocket_codegen)]
3-
extern crate colored;
2+
extern crate futures;
3+
extern crate hyper;
44
#[macro_use]
55
extern crate lazy_static;
6-
extern crate rocket;
6+
extern crate colored;
7+
78
#[macro_use]
89
extern crate serde_derive;
910

@@ -12,8 +13,6 @@ use colored::*;
1213
use file_finder::CTFile;
1314
use man::CTMan;
1415
use ports::CTPorts;
15-
use rocket::http::ContentType;
16-
use rocket::response::Content;
1716
use std::env;
1817
use std::error::Error;
1918
use std::fs::File;
@@ -31,6 +30,14 @@ pub mod banner;
3130
#[macro_use]
3231
pub mod ports_html;
3332

33+
34+
use futures::future;
35+
use hyper::rt::Future;
36+
use hyper::service::service_fn;
37+
use hyper::{Body, Method, Request, Response, Server, StatusCode, HeaderMap};
38+
use hyper::header::CONTENT_TYPE;
39+
40+
3441
pub fn show_banner(){
3542
let show_banner = env::var("CTNOBANNER").unwrap_or("false".to_string());
3643
if show_banner == "false" {
@@ -66,9 +73,10 @@ pub fn init_project(){
6673

6774
pub fn start_port_listening() {
6875
println!("👂 Started ports web server at http://localhost:1500, CTRL+C to exit...");
69-
start_rocket();
76+
start_hyper();
7077
}
7178

79+
7280
pub fn show_man(man_entry: Option<&str>, ct_file: Option<CTFile>) {
7381
if let Some(ct_file) = ct_file {
7482
if let Some(ct_man) = CTMan::all(&ct_file) {
@@ -83,22 +91,46 @@ pub fn show_man(man_entry: Option<&str>, ct_file: Option<CTFile>) {
8391
}
8492
}
8593

86-
#[get("/scan")]
8794
fn scan() -> String {
8895
serde_json::to_string(&CTPorts::all().unwrap()).unwrap()
8996
}
9097

91-
#[get("/", format = "text/html")]
92-
fn home_page() -> Content<String> {
93-
Content(ContentType::HTML, INDEX_HTML!().to_string())
98+
99+
fn home_page() -> &'static str {
100+
INDEX_HTML!()
94101
}
95102

96-
pub fn start_rocket() {
97-
let config = rocket::config::Config::build(rocket::config::Environment::Production)
98-
.port(1500)
99-
.finalize().expect("Could not create config");
103+
type BoxFut = Box<Future<Item = Response<Body>, Error = hyper::Error> + Send>;
104+
105+
fn echo(req: Request<Body>) -> BoxFut {
106+
let mut response = Response::new(Body::empty());
107+
108+
match (req.method(), req.uri().path()) {
109+
(&Method::GET, "/") => {
110+
let mut map = HeaderMap::new();
111+
112+
map.insert(CONTENT_TYPE, "text/html;charset=utf-8".parse().unwrap());
100113

101-
rocket::custom(config, false)
102-
.mount("/", routes![scan, home_page])
103-
.launch();
104-
}
114+
*response.headers_mut() = map;
115+
*response.body_mut() = Body::from(home_page());
116+
}
117+
(&Method::GET, "/scan") => {
118+
*response.body_mut() = Body::from(scan());
119+
}
120+
_ => {
121+
*response.status_mut() = StatusCode::NOT_FOUND;
122+
}
123+
}
124+
Box::new(future::ok(response))
125+
}
126+
127+
pub fn start_hyper() {
128+
let addr = ([0, 0, 0, 0], 1500).into();
129+
130+
let server = Server::bind(&addr)
131+
.serve(|| service_fn(echo))
132+
.map_err(|e| eprintln!("server error: {}", e));
133+
134+
135+
hyper::rt::run(server);
136+
}

0 commit comments

Comments
 (0)