feat: add frontend

This commit is contained in:
2025-12-25 15:59:17 +01:00
parent 24611e05c9
commit 71d915ff0f
65 changed files with 11329 additions and 19 deletions

View File

@@ -1,3 +1,47 @@
fn main() {
println!("Hello, world!");
use std::{env, error::Error};
use actix_files::Files;
use actix_web::{App, HttpResponse, HttpServer, Responder, get, web};
use scp_core::apis::configuration::Configuration;
use scp_core::apis::default_api;
#[get("/api/hello")]
async fn hello() -> impl Responder {
HttpResponse::Ok().json(serde_json::json!({ "message": "hello" }))
}
async fn spa_fallback() -> actix_web::Result<actix_files::NamedFile> {
Ok(actix_files::NamedFile::open("./frontend/dist/index.html")?)
}
#[get("/api/scp/ping")]
async fn ping_netcup() -> impl Responder {
let config = Configuration::default();
let res = default_api::api_ping_get(&config).await;
dbg!(&res);
res.is_ok().to_string()
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let port = env::var("PORT")
.unwrap_or_else(|_| "8080".to_string())
.parse::<u16>()
.unwrap();
HttpServer::new(|| {
App::new()
.service(hello)
.service(ping_netcup)
.service(
Files::new("/", "./frontend/dist")
.index_file("index.html")
.prefer_utf8(true),
)
.default_service(web::route().to(spa_fallback))
})
.bind(("127.0.0.1", port))?
.run()
.await
}