-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02d243a
commit 7ec3b9d
Showing
4 changed files
with
56 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::net::SocketAddr; | ||
use std::path::PathBuf; | ||
use warp::Filter; | ||
|
||
/// Serves the generated app from `.tribble/dist/`. This expects the app to already have been built. | ||
pub async fn serve(dir: PathBuf, host: String, port: u16) { | ||
let dir = dir.join(".tribble/dist"); | ||
// We actually don't have to worry about HTML file extensions at all | ||
let files = warp::any().and(warp::fs::dir(dir)); | ||
// Parse `localhost` into `127.0.0.1` (picky Rust `std`) | ||
let host = if host == "localhost" { | ||
"127.0.0.1".to_string() | ||
} else { | ||
host | ||
}; | ||
// Parse the host and port into an address | ||
let addr: SocketAddr = format!("{}:{}", host, port).parse().unwrap(); | ||
|
||
warp::serve(files).run(addr).await | ||
} |