2017-11-02 00:34:58 +01:00
|
|
|
#![allow(unused_variables)]
|
|
|
|
extern crate actix;
|
|
|
|
extern crate actix_web;
|
|
|
|
extern crate env_logger;
|
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
|
|
|
|
|
|
|
use actix_web::*;
|
|
|
|
|
|
|
|
/// somple handle
|
2017-11-27 06:47:33 +01:00
|
|
|
fn index(req: HttpRequest) -> HttpResponse {
|
2017-11-02 00:34:58 +01:00
|
|
|
println!("{:?}", req);
|
2017-11-09 04:31:25 +01:00
|
|
|
httpcodes::HTTPOk
|
2017-11-27 07:31:29 +01:00
|
|
|
.build()
|
2017-11-09 04:31:25 +01:00
|
|
|
.content_type("text/plain")
|
|
|
|
.body("Welcome!").unwrap()
|
2017-11-02 00:34:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2017-11-04 17:07:44 +01:00
|
|
|
if ::std::env::var("RUST_LOG").is_err() {
|
2017-11-09 04:31:25 +01:00
|
|
|
::std::env::set_var("RUST_LOG", "actix_web=trace");
|
2017-11-04 17:07:44 +01:00
|
|
|
}
|
2017-11-02 00:34:58 +01:00
|
|
|
let _ = env_logger::init();
|
|
|
|
let sys = actix::System::new("ws-example");
|
|
|
|
|
|
|
|
let mut file = File::open("identity.pfx").unwrap();
|
|
|
|
let mut pkcs12 = vec![];
|
|
|
|
file.read_to_end(&mut pkcs12).unwrap();
|
2017-11-04 20:33:14 +01:00
|
|
|
let pkcs12 = Pkcs12::from_der(&pkcs12).unwrap().parse("12345").unwrap();
|
2017-11-02 00:34:58 +01:00
|
|
|
|
|
|
|
HttpServer::new(
|
|
|
|
Application::default("/")
|
|
|
|
// enable logger
|
2017-11-10 21:29:54 +01:00
|
|
|
.middleware(middlewares::Logger::default())
|
2017-11-02 00:34:58 +01:00
|
|
|
// register simple handler, handle all methods
|
|
|
|
.handler("/index.html", index)
|
|
|
|
// with path parameters
|
2017-11-27 06:47:33 +01:00
|
|
|
.resource("/", |r| r.handler(Method::GET, |req| {
|
2017-11-02 00:34:58 +01:00
|
|
|
Ok(httpcodes::HTTPFound
|
2017-11-27 07:31:29 +01:00
|
|
|
.build()
|
2017-11-02 00:34:58 +01:00
|
|
|
.header("LOCATION", "/index.html")
|
|
|
|
.body(Body::Empty)?)
|
|
|
|
})))
|
|
|
|
.serve_tls::<_, ()>("127.0.0.1:8080", pkcs12).unwrap();
|
|
|
|
|
|
|
|
println!("Started http server: 127.0.0.1:8080");
|
|
|
|
let _ = sys.run();
|
|
|
|
}
|