mirror of
https://github.com/hulthe/inkopslista.git
synced 2026-08-03 23:11:28 +02:00
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:
+17
-4
@@ -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()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user