From 729056b75215f3da2f170003e4f558bbe8a4d209 Mon Sep 17 00:00:00 2001 From: Lucas Schumacher Date: Mon, 30 Oct 2023 15:19:03 -0400 Subject: [PATCH] Add static endpoint --- Cargo.lock | 21 +++++++++++++++++++++ Cargo.toml | 2 +- src/main.rs | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d01f843..e23cfa7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1023,6 +1023,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1271,8 +1281,10 @@ dependencies = [ "futures-util", "headers", "http", + "httpdate", "hyper", "mime", + "mime_guess", "multer", "parking_lot", "percent-encoding", @@ -2269,6 +2281,15 @@ dependencies = [ "version_check", ] +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.13" diff --git a/Cargo.toml b/Cargo.toml index 4b242c0..23fd865 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "1.3.58" edition = "2021" [dependencies] -poem = { version = "1.3.58", features = ["websocket", "session", "anyhow"] } +poem = { version = "1.3.58", features = ["websocket", "session", "anyhow", "static-files"] } tokio = { version = "1.17.0", features = ["rt-multi-thread", "macros"] } futures-util = "0.3.17" tracing-subscriber = { version ="0.3.9", features = ["env-filter"] } diff --git a/src/main.rs b/src/main.rs index 469b92f..b7e7b67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ //use bcrypt::{hash, verify, DEFAULT_COST}; use futures_util::{SinkExt, StreamExt}; use poem::{ + endpoint::StaticFilesEndpoint, //get, handler, listener::TcpListener, @@ -289,6 +290,7 @@ async fn main() -> anyhow::Result<()> { "Chat", "0.0", ); + let static_endpoint = StaticFilesEndpoint::new("./client/dist").index_file("index.html"); let app = Route::new() //.at("/api/", get(index)) @@ -297,6 +299,7 @@ async fn main() -> anyhow::Result<()> { // get(ws.data(tokio::sync::broadcast::channel::(32).0)), //) //.data(dbpool) + .nest("/", static_endpoint) .nest("/api", api) .with(session);