m: Option<String>
}
-fn main_page(query: Query<Request>) -> Result<HttpResponse> {
+fn main_page(query: Query<Request>, key: &str) -> Result<HttpResponse> {
let m =
match &query.m {
Some(b) =>
- match crypto::decrypt(KEY, b) {
+ match crypto::decrypt(key, b) {
Ok(m) => m,
Err(_e) => String::from(consts::DEFAULT_MESSAGE) // TODO: log error.
},
}
fn main() -> std::io::Result<()> {
-
let key = read_key();
if process_args(&key) { return Ok(()) }
let mut listenfd = ListenFd::from_env();
let mut server =
HttpServer::new(
- || {
+ move || {
+ let key = key.clone(); // Is this neccessary??
+
App::new()
.wrap(middleware::Compress::default())
.wrap(middleware::Logger::default())
- .service(web::resource("/").to(main_page))
+ .service(web::resource("/").to(move |query| main_page(query, &key)))
.service(fs::Files::new("/static", "static").show_files_listing())
}
);