use actix_web::{App, HttpResponse, HttpServer, Responder, post, web}; use notify_rust::Notification; use serde::Deserialize; #[derive(Deserialize)] struct NotificationData { name: String, body: String, } #[post("/notify")] async fn notify(notification: web::Form) -> impl Responder { let notification = Notification::new() .summary(¬ification.name) .body(¬ification.body) .timeout(0) .show(); match notification { Ok(_) => HttpResponse::Ok().body("{\"status\": \"ok\"}"), Err(err) => HttpResponse::InternalServerError() .body(format!("{{\"status\": \"err\", \"err\": \"{}\"}}", err)), } } #[actix_web::main] async fn main() -> std::io::Result<()> { let host = std::env::var("HOST").unwrap_or(String::from("127.0.0.1")); let port = std::env::var("PORT") .map(|x| x.parse::().unwrap_or(60000)) .unwrap_or(60000); println!( "Starting http server on POST http://{}:{}/notify", host, port ); HttpServer::new(|| App::new().service(notify)) .bind((host, port))? .run() .await }