Merge branch 'master' into shared_array_buffer_as_optional_config
This commit is contained in:
6 files changed
+464
-266
No files matched your search
Generated
+406
-253
File diff suppressed because it is too large.
Load diff
@@ -82,6 +82,7 @@ dioxus-html = { version = "0.3", features = ["hot-reload-context"] }
|
||||
dioxus-core = { version = "0.3", features = ["serialize"] }
|
||||
dioxus-autofmt = "0.3.0"
|
||||
rsx-rosetta = { version = "0.3" }
|
||||
open = "4.1.0"
|
||||
|
||||
[[bin]]
|
||||
path = "src/main.rs"
|
||||
|
||||
@@ -46,4 +46,12 @@ You can use `--example {name}` to start a example code.
|
||||
```
|
||||
# build `example/test` code
|
||||
dioxus serve --exmaple test
|
||||
```
|
||||
```
|
||||
|
||||
## Open Browser
|
||||
|
||||
You can add `--open` flag to open system default browser when server startup.
|
||||
|
||||
```
|
||||
dioxus serve --open
|
||||
```
|
||||
@@ -45,6 +45,11 @@ pub struct ConfigOptsServe {
|
||||
#[clap(default_value_t = 8080)]
|
||||
pub port: u16,
|
||||
|
||||
/// Open the app in the default browser [default: false]
|
||||
#[clap(long)]
|
||||
#[serde(default)]
|
||||
pub open: bool,
|
||||
|
||||
/// Build a example [default: ""]
|
||||
#[clap(long)]
|
||||
pub example: Option<String>,
|
||||
|
||||
@@ -69,7 +69,7 @@ impl Serve {
|
||||
Serve::regen_dev_page(&crate_config)?;
|
||||
|
||||
// start the develop server
|
||||
server::startup(self.serve.port, crate_config.clone()).await?;
|
||||
server::startup(self.serve.port, crate_config.clone(), self.serve.open).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+42
-11
@@ -61,7 +61,7 @@ struct WsReloadState {
|
||||
update: broadcast::Sender<()>,
|
||||
}
|
||||
|
||||
pub async fn startup(port: u16, config: CrateConfig) -> Result<()> {
|
||||
pub async fn startup(port: u16, config: CrateConfig, start_browser: bool) -> Result<()> {
|
||||
// ctrl-c shutdown checker
|
||||
let crate_config = config.clone();
|
||||
let _ = ctrlc::set_handler(move || {
|
||||
@@ -70,10 +70,11 @@ pub async fn startup(port: u16, config: CrateConfig) -> Result<()> {
|
||||
});
|
||||
|
||||
let ip = get_ip().unwrap_or(String::from("0.0.0.0"));
|
||||
|
||||
if config.hot_reload {
|
||||
startup_hot_reload(ip, port, config).await?
|
||||
startup_hot_reload(ip, port, config, start_browser).await?
|
||||
} else {
|
||||
startup_default(ip, port, config).await?
|
||||
startup_default(ip, port, config, start_browser).await?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -135,7 +136,7 @@ pub async fn hot_reload_handler(
|
||||
}
|
||||
|
||||
#[allow(unused_assignments)]
|
||||
pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig) -> Result<()> {
|
||||
pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig, start_browser: bool) -> Result<()> {
|
||||
let first_build_result = crate::builder::build(&config, false)?;
|
||||
|
||||
log::info!("🚀 Starting development server...");
|
||||
@@ -175,6 +176,13 @@ pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig) -> R
|
||||
.clone()
|
||||
.unwrap_or_else(|| vec![PathBuf::from("src")]);
|
||||
|
||||
let cors = CorsLayer::new()
|
||||
// allow `GET` and `POST` when accessing the resource
|
||||
.allow_methods([Method::GET, Method::POST])
|
||||
// allow requests from any origin
|
||||
.allow_origin(Any)
|
||||
.allow_headers(Any);
|
||||
|
||||
let watcher_config = config.clone();
|
||||
let watcher_ip = ip.clone();
|
||||
let mut last_update_time = chrono::Local::now().timestamp();
|
||||
@@ -353,14 +361,25 @@ pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig) -> R
|
||||
.layer(Extension(ws_reload_state))
|
||||
.layer(Extension(hot_reload_state));
|
||||
|
||||
axum::Server::bind(&format!("0.0.0.0:{}", port).parse().unwrap())
|
||||
.serve(router.into_make_service())
|
||||
.await?;
|
||||
let addr = format!("0.0.0.0:{}", port).parse().unwrap();
|
||||
|
||||
let server = axum::Server::bind(&addr).serve(router.into_make_service());
|
||||
|
||||
if start_browser {
|
||||
let _ = open::that(format!("http://{}", addr));
|
||||
}
|
||||
|
||||
server.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn startup_default(ip: String, port: u16, config: CrateConfig) -> Result<()> {
|
||||
pub async fn startup_default(
|
||||
ip: String,
|
||||
port: u16,
|
||||
config: CrateConfig,
|
||||
start_browser: bool,
|
||||
) -> Result<()> {
|
||||
let first_build_result = crate::builder::build(&config, false)?;
|
||||
|
||||
log::info!("🚀 Starting development server...");
|
||||
@@ -380,6 +399,13 @@ pub async fn startup_default(ip: String, port: u16, config: CrateConfig) -> Resu
|
||||
|
||||
let mut last_update_time = chrono::Local::now().timestamp();
|
||||
|
||||
let cors = CorsLayer::new()
|
||||
// allow `GET` and `POST` when accessing the resource
|
||||
.allow_methods([Method::GET, Method::POST])
|
||||
// allow requests from any origin
|
||||
.allow_origin(Any)
|
||||
.allow_headers(Any);
|
||||
|
||||
// file watcher: check file change
|
||||
let allow_watch_path = config
|
||||
.dioxus_config
|
||||
@@ -523,9 +549,14 @@ pub async fn startup_default(ip: String, port: u16, config: CrateConfig) -> Resu
|
||||
.layer(cors)
|
||||
.layer(Extension(ws_reload_state));
|
||||
|
||||
axum::Server::bind(&format!("0.0.0.0:{}", port).parse().unwrap())
|
||||
.serve(router.into_make_service())
|
||||
.await?;
|
||||
let addr = format!("0.0.0.0:{}", port).parse().unwrap();
|
||||
let server = axum::Server::bind(&addr).serve(router.into_make_service());
|
||||
|
||||
if start_browser {
|
||||
let _ = open::that(format!("http://{}", addr));
|
||||
}
|
||||
|
||||
server.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user