diff options
author | stale <redkugelblitzin@gmail.com> | 2022-05-18 09:36:43 -0300 |
---|---|---|
committer | stale <redkugelblitzin@gmail.com> | 2022-05-18 09:36:43 -0300 |
commit | d89b9ea43ac65af549279f6e86c68c66243dcdf3 (patch) | |
tree | 39173297e076c4425149c78f6244a2b762786ac8 /src/main.rs | |
parent | 127a1059fec4fecb4099cb95ddb7ef3c7cf45077 (diff) |
organizing
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs index 0a17346..e972025 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ use std::{ net::SocketAddr, sync::Arc, }; -use warp::Filter; mod types; mod conn; @@ -12,13 +11,16 @@ use types::*; use tokio::sync::RwLock; -const FONT_FILE: &[u8] = include_bytes!("./VT323-Regular.ttf"); +const FONT_FILE: &[u8] = include_bytes!("../assets/VT323-Regular.ttf"); fn main() -> Result<(), Box<dyn Error>> { let conf = Config { - cert_path: "./cert.pem".to_owned(), - pkey_path: "./cert.rsa".to_owned(), - page_path: "./page.html".to_owned(), + cert: "./cert.pem".to_owned(), + pkey: "./cert.rsa".to_owned(), + room_pg: "./assets/room.html".to_owned(), + form_pg: "./assets/form.html".to_owned(), + client_code: "./assets/client.js".to_owned(), + stylesheet: "./assets/style.css".to_owned(), socket_addr: ([0,0,0,0],31235).into(), }; @@ -44,13 +46,14 @@ async fn tokio_main(conf: Config) -> Result<(), Box<dyn Error>> { } })); - let page_route = { - use warp::*; - get() - .and(path("font.ttf")) - .map(|| FONT_FILE) - .or(fs::file(conf.page_path.clone())) - }; + use warp::*; + + let style = path("s.css").and(fs::file(conf.stylesheet.clone())); + let code = path("c.js").and(fs::file(conf.client_code.clone())); + let font = path("f.ttf").map(|| FONT_FILE); + let listing = path("rlist").map(|| "placeholder'em"); + let room_form = path("r").map(|| "yeah placeholder mate"); + let index = path::end().and(fs::file(conf.room_pg.clone())); let websocket_route = { let room = room.clone(); @@ -66,12 +69,13 @@ async fn tokio_main(conf: Config) -> Result<(), Box<dyn Error>> { }) }) }; - let routes = websocket_route.or(page_route); + let route = any().and(get().and(index).or(style).or(code).or(font).or(listing)).or(post().and(room_form)); + let routes = websocket_route.or(route); let server = warp::serve(routes) .tls() - .cert_path(conf.cert_path) - .key_path(conf.pkey_path) + .cert_path(conf.cert) + .key_path(conf.pkey) .run(conf.socket_addr); println!("Serving on {}", conf.socket_addr); server.await; |