Support front end deployment

This commit is contained in:
2026-04-02 00:53:25 -04:00
parent 36629ab436
commit 55b37e5156
5 changed files with 63 additions and 5 deletions

View File

@@ -8,9 +8,10 @@ use actix_web::{web, App,
HttpResponse,
HttpServer,
http::header::ContentType,
Responder,
Responder, Result
};
use actix_cors::Cors;
use actix_files::{Files, NamedFile};
use serde::Deserialize;
use database as db;
use database::DidTargetType;
@@ -47,7 +48,6 @@ async fn route_did(request: web::Form<RouteRequest>) -> impl Responder {
async fn did_post(d: web::Json<JsonDid>) -> impl Responder {
let did = d.deref();
println!("{:?}", did);
db::add_did(&did.did_number, &did.target_type, &did.target, did.active ,&did.trunk).unwrap();
HttpResponse::Ok().body("DID added.")
}
@@ -107,14 +107,19 @@ fn api_config(cfg: &mut web::ServiceConfig) {
);
}
async fn index() -> Result<NamedFile> {
Ok(NamedFile::open("/var/www/did_router/index.html")?)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
let cors = Cors::permissive();
App::new()
.wrap(cors)
.service(Files::new("/admin", "/var/www/did_router/").index_file("index.html"))
.service(
web::scope("/api").configure(api_config))
.default_service(web::route().to(index))
})
.bind(("0.0.0.0", 3000))?
.run()