get the dioxus CLI compiling
This commit is contained in:
1 parent
30af559275
commit
e7d8a25d17
8 files changed
+40
-42
No files matched your search
Generated
+1
@@ -2275,6 +2275,7 @@ dependencies = [
|
|||||||
"html_parser",
|
"html_parser",
|
||||||
"hyper 1.1.0",
|
"hyper 1.1.0",
|
||||||
"hyper-rustls 0.26.0",
|
"hyper-rustls 0.26.0",
|
||||||
|
"hyper-util",
|
||||||
"ignore",
|
"ignore",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"interprocess-docfix",
|
"interprocess-docfix",
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ atty = "0.2.14"
|
|||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
hyper = { workspace = true }
|
hyper = { workspace = true }
|
||||||
|
hyper-util = "0.1.3"
|
||||||
hyper-rustls = { workspace = true }
|
hyper-rustls = { workspace = true }
|
||||||
indicatif = "0.17.5"
|
indicatif = "0.17.5"
|
||||||
subprocess = "0.2.9"
|
subprocess = "0.2.9"
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ use axum::{
|
|||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Extension,
|
Extension,
|
||||||
};
|
};
|
||||||
use axum_extra::TypedHeader;
|
|
||||||
|
|
||||||
pub async fn hot_reload_handler(
|
pub async fn hot_reload_handler(
|
||||||
ws: WebSocketUpgrade,
|
ws: WebSocketUpgrade,
|
||||||
_: Option<TypedHeader<headers::UserAgent>>,
|
|
||||||
Extension(state): Extension<HotReloadState>,
|
Extension(state): Extension<HotReloadState>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
ws.on_upgrade(|mut socket| async move {
|
ws.on_upgrade(|mut socket| async move {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
BuildResult, Result,
|
BuildResult, Result,
|
||||||
};
|
};
|
||||||
use axum::{
|
use axum::{
|
||||||
body::{Body, HttpBody},
|
body::Body,
|
||||||
extract::{ws::Message, Extension, WebSocketUpgrade},
|
extract::{ws::Message, Extension, WebSocketUpgrade},
|
||||||
http::{
|
http::{
|
||||||
self,
|
self,
|
||||||
@@ -19,8 +19,7 @@ use axum::{
|
|||||||
routing::{get, get_service},
|
routing::{get, get_service},
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use axum_extra::TypedHeader;
|
use axum_server::tls_rustls::RustlsConfig;
|
||||||
use axum_server::{service::SendService, tls_rustls::RustlsConfig};
|
|
||||||
use dioxus_cli_config::CrateConfig;
|
use dioxus_cli_config::CrateConfig;
|
||||||
use dioxus_cli_config::WebHttpsConfig;
|
use dioxus_cli_config::WebHttpsConfig;
|
||||||
|
|
||||||
@@ -299,9 +298,7 @@ async fn setup_router(
|
|||||||
.body(body)
|
.body(body)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
} else {
|
} else {
|
||||||
response.map(|body| body.try_into().unwrap())
|
response.into_response()
|
||||||
// response.into_body()
|
|
||||||
// response.map(|body| body.into())
|
|
||||||
};
|
};
|
||||||
let headers = response.headers_mut();
|
let headers = response.headers_mut();
|
||||||
headers.insert(
|
headers.insert(
|
||||||
@@ -316,7 +313,7 @@ async fn setup_router(
|
|||||||
.service(ServeDir::new(config.out_dir()));
|
.service(ServeDir::new(config.out_dir()));
|
||||||
|
|
||||||
// Setup websocket
|
// Setup websocket
|
||||||
let mut router = Router::new().route("/_dioxus/ws", get(ws_handler.into()));
|
let mut router = Router::new().route("/_dioxus/ws", get(ws_handler));
|
||||||
|
|
||||||
// Setup proxy
|
// Setup proxy
|
||||||
for proxy_config in config.dioxus_config.web.proxy {
|
for proxy_config in config.dioxus_config.web.proxy {
|
||||||
@@ -324,8 +321,8 @@ async fn setup_router(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Route file service
|
// Route file service
|
||||||
router = router.fallback(get_service(file_service.into_service()).handle_error(
|
router = router.fallback(get_service(file_service).handle_error(
|
||||||
|error: std::io::Error| async move {
|
|error: std::convert::Infallible| async move {
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
format!("Unhandled internal error: {}", error),
|
format!("Unhandled internal error: {}", error),
|
||||||
@@ -336,7 +333,7 @@ async fn setup_router(
|
|||||||
router = if let Some(base_path) = config.dioxus_config.web.app.base_path.clone() {
|
router = if let Some(base_path) = config.dioxus_config.web.app.base_path.clone() {
|
||||||
let base_path = format!("/{}", base_path.trim_matches('/'));
|
let base_path = format!("/{}", base_path.trim_matches('/'));
|
||||||
Router::new()
|
Router::new()
|
||||||
.route(&base_path, axum::routing::any_service(router.into()))
|
.route(&base_path, axum::routing::any_service(router))
|
||||||
.fallback(get(move || {
|
.fallback(get(move || {
|
||||||
let base_path = base_path.clone();
|
let base_path = base_path.clone();
|
||||||
async move { format!("Outside of the base path: {}", base_path) }
|
async move { format!("Outside of the base path: {}", base_path) }
|
||||||
@@ -347,7 +344,7 @@ async fn setup_router(
|
|||||||
|
|
||||||
// Setup routes
|
// Setup routes
|
||||||
router = router
|
router = router
|
||||||
.route("/_dioxus/hot_reload", get(hot_reload_handler.into()))
|
.route("/_dioxus/hot_reload", get(hot_reload_handler))
|
||||||
.layer(cors)
|
.layer(cors)
|
||||||
.layer(Extension(ws_reload));
|
.layer(Extension(ws_reload));
|
||||||
|
|
||||||
@@ -418,7 +415,6 @@ fn get_ip() -> Option<String> {
|
|||||||
/// Handle websockets
|
/// Handle websockets
|
||||||
async fn ws_handler(
|
async fn ws_handler(
|
||||||
ws: WebSocketUpgrade,
|
ws: WebSocketUpgrade,
|
||||||
_: Option<TypedHeader<headers::UserAgent>>,
|
|
||||||
Extension(state): Extension<Arc<WsReloadState>>,
|
Extension(state): Extension<Arc<WsReloadState>>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
ws.on_upgrade(|mut socket| async move {
|
ws.on_upgrade(|mut socket| async move {
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
use crate::Result;
|
use crate::Result;
|
||||||
use dioxus_cli_config::WebProxyConfig;
|
use dioxus_cli_config::WebProxyConfig;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::{anyhow, Context};
|
||||||
use axum::{http::StatusCode, routing::any, Router};
|
use axum::{http::StatusCode, routing::any, Router};
|
||||||
use hyper::{Request, Response, Uri};
|
use hyper::{Request, Response, Uri};
|
||||||
use hyper::client::legacy::Client;
|
use hyper_util::{
|
||||||
|
client::legacy::{self, connect::HttpConnector},
|
||||||
|
rt::TokioExecutor,
|
||||||
|
};
|
||||||
|
|
||||||
use axum::body::Body as MyBody;
|
use axum::body::Body as MyBody;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct ProxyClient {
|
struct ProxyClient {
|
||||||
inner: Client<hyper_rustls::HttpsConnector<Client::HttpConnector>>,
|
inner: legacy::Client<hyper_rustls::HttpsConnector<HttpConnector>, MyBody>,
|
||||||
url: Uri,
|
url: Uri,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,12 +26,12 @@ impl ProxyClient {
|
|||||||
.enable_http1()
|
.enable_http1()
|
||||||
.build();
|
.build();
|
||||||
Self {
|
Self {
|
||||||
inner: Client::builder().build(https),
|
inner: legacy::Client::builder(TokioExecutor::new()).build(https),
|
||||||
url,
|
url,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send(&self, mut req: Request<MyBody>) -> Result<Response<MyBody>> {
|
async fn send(&self, mut req: Request<MyBody>) -> Result<Response<hyper::body::Incoming>> {
|
||||||
let mut uri_parts = req.uri().clone().into_parts();
|
let mut uri_parts = req.uri().clone().into_parts();
|
||||||
uri_parts.authority = self.url.authority().cloned();
|
uri_parts.authority = self.url.authority().cloned();
|
||||||
uri_parts.scheme = self.url.scheme().cloned();
|
uri_parts.scheme = self.url.scheme().cloned();
|
||||||
@@ -36,7 +39,7 @@ impl ProxyClient {
|
|||||||
self.inner
|
self.inner
|
||||||
.request(req)
|
.request(req)
|
||||||
.await
|
.await
|
||||||
.map_err(crate::error::Error::ProxyRequestError)
|
.map_err(|err| crate::error::Error::Other(anyhow!(err)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,14 +115,14 @@ mod test {
|
|||||||
"/*path",
|
"/*path",
|
||||||
any(|path: Path<String>| async move { format!("backend: {}", path.0) }),
|
any(|path: Path<String>| async move { format!("backend: {}", path.0) }),
|
||||||
);
|
);
|
||||||
let backend_server = Server::bind(&"127.0.0.1:0".parse().unwrap())
|
let backend_server =
|
||||||
.serve(backend_router.into_make_service());
|
Server::bind("127.0.0.1:0".parse().unwrap()).serve(backend_router.into_make_service());
|
||||||
let backend_addr = backend_server.local_addr();
|
let backend_addr = backend_server.local_addr();
|
||||||
let backend_handle = tokio::spawn(async move { backend_server.await.unwrap() });
|
let backend_handle = tokio::spawn(async move { backend_server.await.unwrap() });
|
||||||
config.backend = format!("http://{}{}", backend_addr, config.backend);
|
config.backend = format!("http://{}{}", backend_addr, config.backend);
|
||||||
let router = super::add_proxy(Router::new(), &config);
|
let router = super::add_proxy(Router::new(), &config);
|
||||||
let server = Server::bind("127.0.0.1:0".parse().unwrap())
|
let server =
|
||||||
.serve(router.unwrap().into_make_service());
|
Server::bind("127.0.0.1:0".parse().unwrap()).serve(router.unwrap().into_make_service());
|
||||||
let server_addr = server.local_addr();
|
let server_addr = server.local_addr();
|
||||||
let server_handle = tokio::spawn(async move { server.await.unwrap() });
|
let server_handle = tokio::spawn(async move { server.await.unwrap() });
|
||||||
(backend_handle, server_handle, server_addr.to_string())
|
(backend_handle, server_handle, server_addr.to_string())
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
use axum::routing::*;
|
||||||
use axum::{
|
use axum::{
|
||||||
body::{self, Body},
|
body::{self, Body},
|
||||||
extract::State,
|
extract::State,
|
||||||
@@ -63,12 +64,11 @@ use axum::{
|
|||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use dioxus_lib::prelude::VirtualDom;
|
use dioxus_lib::prelude::VirtualDom;
|
||||||
|
use http::header::*;
|
||||||
use server_fn::error::NoCustomError;
|
use server_fn::error::NoCustomError;
|
||||||
use server_fn::error::ServerFnErrorSerde;
|
use server_fn::error::ServerFnErrorSerde;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
use axum::routing::*;
|
|
||||||
use http::header::*;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
prelude::*, render::SSRState, serve_config::ServeConfig, server_context::DioxusServerContext,
|
prelude::*, render::SSRState, serve_config::ServeConfig, server_context::DioxusServerContext,
|
||||||
@@ -196,12 +196,12 @@ where
|
|||||||
|
|
||||||
for (path, method) in server_fn::axum::server_fn_paths() {
|
for (path, method) in server_fn::axum::server_fn_paths() {
|
||||||
tracing::trace!("Registering server function: {} {}", method, path);
|
tracing::trace!("Registering server function: {} {}", method, path);
|
||||||
let handler = move |req| handle_server_fns_inner(path, ||{}, req);
|
let handler = move |req| handle_server_fns_inner(path, || {}, req);
|
||||||
self = match method {
|
self = match method {
|
||||||
Method::GET => self.route(path, get(handler)),
|
Method::GET => self.route(path, get(handler)),
|
||||||
Method::POST => self.route(path, post(handler)),
|
Method::POST => self.route(path, post(handler)),
|
||||||
Method::PUT => self.route(path, put(handler)),
|
Method::PUT => self.route(path, put(handler)),
|
||||||
_ => todo!()
|
_ => todo!(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,4 +548,4 @@ async fn handle_server_fns_inner(
|
|||||||
)
|
)
|
||||||
.into_response()
|
.into_response()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,6 @@ pub mod launch;
|
|||||||
mod hot_reload;
|
mod hot_reload;
|
||||||
pub use config::*;
|
pub use config::*;
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
mod render;
|
mod render;
|
||||||
|
|
||||||
@@ -73,8 +72,8 @@ pub mod prelude {
|
|||||||
#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
|
||||||
pub use dioxus_ssr::incremental::IncrementalRendererConfig;
|
pub use dioxus_ssr::incremental::IncrementalRendererConfig;
|
||||||
|
|
||||||
pub use server_fn::{self, ServerFn as _, ServerFnError};
|
|
||||||
pub use dioxus_server_macro::*;
|
pub use dioxus_server_macro::*;
|
||||||
|
pub use server_fn::{self, ServerFn as _, ServerFnError};
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Warn users about overlapping features
|
// // Warn users about overlapping features
|
||||||
|
|||||||
@@ -70,15 +70,15 @@ use syn::__private::ToTokens;
|
|||||||
/// ```
|
/// ```
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn server(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
|
pub fn server(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
|
||||||
match server_macro_impl(
|
match server_macro_impl(
|
||||||
args.into(),
|
args.into(),
|
||||||
s.into(),
|
s.into(),
|
||||||
Some(syn::parse_quote!(server_fn)),
|
Some(syn::parse_quote!(server_fn)),
|
||||||
"/api",
|
"/api",
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
) {
|
) {
|
||||||
Err(e) => e.to_compile_error().into(),
|
Err(e) => e.to_compile_error().into(),
|
||||||
Ok(s) => s.to_token_stream().into(),
|
Ok(s) => s.to_token_stream().into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user