-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): added inbuilt server for exported apps
No more `serve`!
- Loading branch information
1 parent
dccd25e
commit 8274678
Showing
7 changed files
with
73 additions
and
11 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
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,30 @@ | ||
use console::Emoji; | ||
use std::net::SocketAddr; | ||
use std::path::PathBuf; | ||
use warp::Filter; | ||
|
||
static SERVING: Emoji<'_, '_> = Emoji("🛰️ ", ""); | ||
|
||
/// Serves an exported app, assuming it's already been exported. | ||
pub async fn serve_exported(dir: PathBuf, host: String, port: u16) { | ||
let dir = dir.join(".perseus/dist/exported"); | ||
// 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(); | ||
// Notify the user that we're serving their files | ||
println!( | ||
" [3/3] {} Your exported app is now live at <http://{host}:{port}>!", | ||
SERVING, | ||
host = host, | ||
port = port | ||
); | ||
|
||
warp::serve(files).run(addr).await | ||
} |