feat: add frontend
This commit is contained in:
48
src/main.rs
48
src/main.rs
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user