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;
|
|
|
|
|
2017-12-30 21:05:03 +01:00
|
|
|
use actix::*;
|
2017-11-02 00:34:58 +01:00
|
|
|
use actix_web::*;
|
2017-12-30 21:05:03 +01:00
|
|
|
#[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
|
2017-11-02 00:34:58 +01:00
|
|
|
|
|
|
|
/// somple handle
|
2017-11-29 23:03:18 +01:00
|
|
|
fn index(req: HttpRequest) -> Result<HttpResponse> {
|
2017-11-02 00:34:58 +01:00
|
|
|
println!("{:?}", req);
|
2017-11-29 23:03:18 +01:00
|
|
|
Ok(httpcodes::HTTPOk
|
|
|
|
.build()
|
|
|
|
.content_type("text/plain")
|
|
|
|
.body("Welcome!")?)
|
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
|
|
|
|
2017-12-30 16:24:50 +01:00
|
|
|
let addr = HttpServer::new(
|
2017-12-13 02:21:00 +01:00
|
|
|
|| Application::new()
|
2017-11-02 00:34:58 +01:00
|
|
|
// enable logger
|
2017-12-27 04:59:41 +01:00
|
|
|
.middleware(middleware::Logger::default())
|
2017-11-02 00:34:58 +01:00
|
|
|
// register simple handler, handle all methods
|
2017-12-08 03:08:16 +01:00
|
|
|
.resource("/index.html", |r| r.f(index))
|
2017-11-02 00:34:58 +01:00
|
|
|
// with path parameters
|
2017-12-05 01:32:31 +01:00
|
|
|
.resource("/", |r| r.method(Method::GET).f(|req| {
|
2017-11-29 23:03:18 +01:00
|
|
|
httpcodes::HTTPFound
|
|
|
|
.build()
|
|
|
|
.header("LOCATION", "/index.html")
|
|
|
|
.body(Body::Empty)
|
2017-11-02 00:34:58 +01:00
|
|
|
})))
|
2017-12-18 22:06:41 +01:00
|
|
|
.bind("127.0.0.1:8443").unwrap()
|
|
|
|
.start_ssl(&pkcs12).unwrap();
|
2017-11-02 00:34:58 +01:00
|
|
|
|
2017-12-30 21:05:03 +01:00
|
|
|
if cfg!(target_os = "linux") { // Subscribe to unix signals
|
|
|
|
let signals = Arbiter::system_registry().get::<ProcessSignals>();
|
|
|
|
signals.send(Subscribe(addr.subscriber()));
|
|
|
|
}
|
2017-12-30 16:24:50 +01:00
|
|
|
|
2017-12-06 02:09:15 +01:00
|
|
|
println!("Started http server: 127.0.0.1:8443");
|
2017-11-02 00:34:58 +01:00
|
|
|
let _ = sys.run();
|
|
|
|
}
|