Add static endpoint

This commit is contained in:
Lucas Schumacher 2023-10-30 15:19:03 -04:00
parent 1dd0b7caaa
commit 729056b752
3 changed files with 25 additions and 1 deletions

21
Cargo.lock generated
View File

@ -1023,6 +1023,16 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" 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]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@ -1271,8 +1281,10 @@ dependencies = [
"futures-util", "futures-util",
"headers", "headers",
"http", "http",
"httpdate",
"hyper", "hyper",
"mime", "mime",
"mime_guess",
"multer", "multer",
"parking_lot", "parking_lot",
"percent-encoding", "percent-encoding",
@ -2269,6 +2281,15 @@ dependencies = [
"version_check", "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]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.13" version = "0.3.13"

View File

@ -4,7 +4,7 @@ version = "1.3.58"
edition = "2021" edition = "2021"
[dependencies] [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"] } tokio = { version = "1.17.0", features = ["rt-multi-thread", "macros"] }
futures-util = "0.3.17" futures-util = "0.3.17"
tracing-subscriber = { version ="0.3.9", features = ["env-filter"] } tracing-subscriber = { version ="0.3.9", features = ["env-filter"] }

View File

@ -2,6 +2,7 @@
//use bcrypt::{hash, verify, DEFAULT_COST}; //use bcrypt::{hash, verify, DEFAULT_COST};
use futures_util::{SinkExt, StreamExt}; use futures_util::{SinkExt, StreamExt};
use poem::{ use poem::{
endpoint::StaticFilesEndpoint,
//get, //get,
handler, handler,
listener::TcpListener, listener::TcpListener,
@ -289,6 +290,7 @@ async fn main() -> anyhow::Result<()> {
"Chat", "Chat",
"0.0", "0.0",
); );
let static_endpoint = StaticFilesEndpoint::new("./client/dist").index_file("index.html");
let app = Route::new() let app = Route::new()
//.at("/api/", get(index)) //.at("/api/", get(index))
@ -297,6 +299,7 @@ async fn main() -> anyhow::Result<()> {
// get(ws.data(tokio::sync::broadcast::channel::<String>(32).0)), // get(ws.data(tokio::sync::broadcast::channel::<String>(32).0)),
//) //)
//.data(dbpool) //.data(dbpool)
.nest("/", static_endpoint)
.nest("/api", api) .nest("/api", api)
.with(session); .with(session);