1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-02-02 18:59:04 +01:00

61 lines
1.7 KiB
Rust
Raw Normal View History

#![allow(unused_variables)]
extern crate actix;
extern crate actix_web;
extern crate env_logger;
use std::fs::File;
use std::io::Read;
use actix::*;
use actix_web::*;
2017-12-31 21:55:25 -08:00
#[cfg(unix)]
2017-12-31 13:22:11 -08:00
use actix::actors::signal::{ProcessSignals, Subscribe};
/// somple handle
2017-11-29 14:03:18 -08:00
fn index(req: HttpRequest) -> Result<HttpResponse> {
println!("{:?}", req);
2017-11-29 14:03:18 -08:00
Ok(httpcodes::HTTPOk
.build()
.content_type("text/plain")
.body("Welcome!")?)
}
fn main() {
2017-11-04 09:07:44 -07:00
if ::std::env::var("RUST_LOG").is_err() {
2017-11-08 19:31:25 -08:00
::std::env::set_var("RUST_LOG", "actix_web=trace");
2017-11-04 09:07:44 -07: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();
let pkcs12 = Pkcs12::from_der(&pkcs12).unwrap().parse("12345").unwrap();
2017-12-30 16:24:50 +01:00
let addr = HttpServer::new(
|| Application::new()
// enable logger
2017-12-26 19:59:41 -08:00
.middleware(middleware::Logger::default())
// register simple handler, handle all methods
2017-12-07 18:08:16 -08:00
.resource("/index.html", |r| r.f(index))
// with path parameters
2017-12-04 16:32:31 -08:00
.resource("/", |r| r.method(Method::GET).f(|req| {
2017-11-29 14:03:18 -08:00
httpcodes::HTTPFound
.build()
.header("LOCATION", "/index.html")
.body(Body::Empty)
})))
2017-12-18 13:06:41 -08:00
.bind("127.0.0.1:8443").unwrap()
.start_ssl(&pkcs12).unwrap();
2017-12-31 13:22:11 -08:00
// Subscribe to unix signals
2017-12-31 21:55:25 -08:00
#[cfg(unix)]
2017-12-31 13:22:11 -08:00
{
2018-01-03 19:11:40 -08:00
let signals = actix::Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber()));
}
2017-12-30 16:24:50 +01:00
2017-12-05 17:09:15 -08:00
println!("Started http server: 127.0.0.1:8443");
let _ = sys.run();
}