Serve gui from server

The server will serve all files in the ./www directory relative to
itself. The ./www/pkg is populated when running

    wasm-pack build --release --target web

from the /gui directory
This commit is contained in:
2025-12-29 19:25:33 +01:00
parent 70b097905c
commit 759c37d76c
+17 -4
View File
@@ -1,15 +1,27 @@
#[macro_use]
extern crate rocket;
use std::env;
use std::{env, path::Path};
use inkopslista_lib::{Item, ItemData};
use rocket::{serde::json::Json, State};
use rocket::{
fs::{FileServer, NamedFile},
serde::json::Json,
State,
};
use sqlite::ConnectionThreadSafe;
/// The directory where the web files for the gui is stored.
fn www_path() -> &'static Path {
Path::new("./www")
}
/// Serve `index.html` from [`www_path`].
#[get("/")]
fn index() -> &'static str {
"hello world"
async fn index() -> NamedFile {
NamedFile::open(www_path().join("index.html"))
.await
.expect("index.html")
}
#[get("/api/list")]
@@ -67,4 +79,5 @@ fn rocket() -> _ {
rocket::build()
.manage(db)
.mount("/", routes![index, get_list, put_list, delete_item])
.mount("/", FileServer::from(www_path()))
}