2017-11-01 16:34:58 -07:00
|
|
|
#![allow(unused_variables)]
|
|
|
|
extern crate actix;
|
|
|
|
extern crate actix_web;
|
|
|
|
extern crate env_logger;
|
2018-01-25 10:24:04 -08:00
|
|
|
extern crate openssl;
|
2017-11-01 16:34:58 -07:00
|
|
|
|
2018-01-25 10:24:04 -08:00
|
|
|
use openssl::ssl::{SslMethod, SslAcceptor, SslFiletype};
|
2018-03-30 18:54:38 -07:00
|
|
|
use actix_web::{
|
2018-03-31 00:16:55 -07:00
|
|
|
http, middleware, server, App, HttpRequest, HttpResponse, Error};
|
2018-01-05 16:32:36 -08:00
|
|
|
|
2017-11-01 16:34:58 -07:00
|
|
|
|
2018-01-16 21:59:33 +03:00
|
|
|
/// simple handle
|
2018-03-30 18:54:38 -07:00
|
|
|
fn index(req: HttpRequest) -> Result<HttpResponse, Error> {
|
2017-11-01 16:34:58 -07:00
|
|
|
println!("{:?}", req);
|
2018-03-30 18:54:38 -07:00
|
|
|
Ok(HttpResponse::Ok()
|
2017-11-29 14:03:18 -08:00
|
|
|
.content_type("text/plain")
|
2018-03-30 23:37:15 -07:00
|
|
|
.body("Welcome!"))
|
2017-11-01 16:34:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2017-11-04 09:07:44 -07:00
|
|
|
if ::std::env::var("RUST_LOG").is_err() {
|
2018-01-25 10:24:04 -08:00
|
|
|
::std::env::set_var("RUST_LOG", "actix_web=info");
|
2017-11-04 09:07:44 -07:00
|
|
|
}
|
2018-03-30 18:54:38 -07:00
|
|
|
env_logger::init();
|
2017-11-01 16:34:58 -07:00
|
|
|
let sys = actix::System::new("ws-example");
|
|
|
|
|
2018-01-25 10:24:04 -08:00
|
|
|
// load ssl keys
|
|
|
|
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
|
|
|
|
builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap();
|
|
|
|
builder.set_certificate_chain_file("cert.pem").unwrap();
|
2017-11-01 16:34:58 -07:00
|
|
|
|
2018-03-30 18:54:38 -07:00
|
|
|
let _ = server::new(
|
2018-03-31 00:16:55 -07:00
|
|
|
|| App::new()
|
2017-11-01 16:34:58 -07:00
|
|
|
// enable logger
|
2017-12-26 19:59:41 -08:00
|
|
|
.middleware(middleware::Logger::default())
|
2017-11-01 16:34:58 -07:00
|
|
|
// register simple handler, handle all methods
|
2017-12-07 18:08:16 -08:00
|
|
|
.resource("/index.html", |r| r.f(index))
|
2017-11-01 16:34:58 -07:00
|
|
|
// with path parameters
|
2018-03-30 18:54:38 -07:00
|
|
|
.resource("/", |r| r.method(http::Method::GET).f(|req| {
|
|
|
|
HttpResponse::Found()
|
2017-11-29 14:03:18 -08:00
|
|
|
.header("LOCATION", "/index.html")
|
2018-03-30 18:54:38 -07:00
|
|
|
.finish()
|
2017-11-01 16:34:58 -07:00
|
|
|
})))
|
2017-12-18 13:06:41 -08:00
|
|
|
.bind("127.0.0.1:8443").unwrap()
|
2018-01-25 10:24:04 -08:00
|
|
|
.start_ssl(builder).unwrap();
|
2017-11-01 16:34:58 -07:00
|
|
|
|
2017-12-05 17:09:15 -08:00
|
|
|
println!("Started http server: 127.0.0.1:8443");
|
2017-11-01 16:34:58 -07:00
|
|
|
let _ = sys.run();
|
|
|
|
}
|