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
@@ -33,6 +33,7 @@ atty = "0.2.14"
|
||||
chrono = "0.4.19"
|
||||
anyhow = "1"
|
||||
hyper = { workspace = true }
|
||||
hyper-util = "0.1.3"
|
||||
hyper-rustls = { workspace = true }
|
||||
indicatif = "0.17.5"
|
||||
subprocess = "0.2.9"
|
||||
|
||||
@@ -4,11 +4,9 @@ use axum::{
|
||||
response::IntoResponse,
|
||||
Extension,
|
||||
};
|
||||
use axum_extra::TypedHeader;
|
||||
|
||||
pub async fn hot_reload_handler(
|
||||
ws: WebSocketUpgrade,
|
||||
_: Option<TypedHeader<headers::UserAgent>>,
|
||||
Extension(state): Extension<HotReloadState>,
|
||||
) -> impl IntoResponse {
|
||||
ws.on_upgrade(|mut socket| async move {
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
BuildResult, Result,
|
||||
};
|
||||
use axum::{
|
||||
body::{Body, HttpBody},
|
||||
body::Body,
|
||||
extract::{ws::Message, Extension, WebSocketUpgrade},
|
||||
http::{
|
||||
self,
|
||||
@@ -19,8 +19,7 @@ use axum::{
|
||||
routing::{get, get_service},
|
||||
Router,
|
||||
};
|
||||
use axum_extra::TypedHeader;
|
||||
use axum_server::{service::SendService, tls_rustls::RustlsConfig};
|
||||
use axum_server::tls_rustls::RustlsConfig;
|
||||
use dioxus_cli_config::CrateConfig;
|
||||
use dioxus_cli_config::WebHttpsConfig;
|
||||
|
||||
@@ -299,9 +298,7 @@ async fn setup_router(
|
||||
.body(body)
|
||||
.unwrap()
|
||||
} else {
|
||||
response.map(|body| body.try_into().unwrap())
|
||||
// response.into_body()
|
||||
// response.map(|body| body.into())
|
||||
response.into_response()
|
||||
};
|
||||
let headers = response.headers_mut();
|
||||
headers.insert(
|
||||
@@ -316,7 +313,7 @@ async fn setup_router(
|
||||
.service(ServeDir::new(config.out_dir()));
|
||||
|
||||
// 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
|
||||
for proxy_config in config.dioxus_config.web.proxy {
|
||||
@@ -324,8 +321,8 @@ async fn setup_router(
|
||||
}
|
||||
|
||||
// Route file service
|
||||
router = router.fallback(get_service(file_service.into_service()).handle_error(
|
||||
|error: std::io::Error| async move {
|
||||
router = router.fallback(get_service(file_service).handle_error(
|
||||
|error: std::convert::Infallible| async move {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_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() {
|
||||
let base_path = format!("/{}", base_path.trim_matches('/'));
|
||||
Router::new()
|
||||
.route(&base_path, axum::routing::any_service(router.into()))
|
||||
.route(&base_path, axum::routing::any_service(router))
|
||||
.fallback(get(move || {
|
||||
let base_path = base_path.clone();
|
||||
async move { format!("Outside of the base path: {}", base_path) }
|
||||
@@ -347,7 +344,7 @@ async fn setup_router(
|
||||
|
||||
// Setup routes
|
||||
router = router
|
||||
.route("/_dioxus/hot_reload", get(hot_reload_handler.into()))
|
||||
.route("/_dioxus/hot_reload", get(hot_reload_handler))
|
||||
.layer(cors)
|
||||
.layer(Extension(ws_reload));
|
||||
|
||||
@@ -418,7 +415,6 @@ fn get_ip() -> Option<String> {
|
||||
/// Handle websockets
|
||||
async fn ws_handler(
|
||||
ws: WebSocketUpgrade,
|
||||
_: Option<TypedHeader<headers::UserAgent>>,
|
||||
Extension(state): Extension<Arc<WsReloadState>>,
|
||||
) -> impl IntoResponse {
|
||||
ws.on_upgrade(|mut socket| async move {
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
use crate::Result;
|
||||
use dioxus_cli_config::WebProxyConfig;
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::{anyhow, Context};
|
||||
use axum::{http::StatusCode, routing::any, Router};
|
||||
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;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct ProxyClient {
|
||||
inner: Client<hyper_rustls::HttpsConnector<Client::HttpConnector>>,
|
||||
inner: legacy::Client<hyper_rustls::HttpsConnector<HttpConnector>, MyBody>,
|
||||
url: Uri,
|
||||
}
|
||||
|
||||
@@ -23,12 +26,12 @@ impl ProxyClient {
|
||||
.enable_http1()
|
||||
.build();
|
||||
Self {
|
||||
inner: Client::builder().build(https),
|
||||
inner: legacy::Client::builder(TokioExecutor::new()).build(https),
|
||||
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();
|
||||
uri_parts.authority = self.url.authority().cloned();
|
||||
uri_parts.scheme = self.url.scheme().cloned();
|
||||
@@ -36,7 +39,7 @@ impl ProxyClient {
|
||||
self.inner
|
||||
.request(req)
|
||||
.await
|
||||
.map_err(crate::error::Error::ProxyRequestError)
|
||||
.map_err(|err| crate::error::Error::Other(anyhow!(err)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,14 +115,14 @@ mod test {
|
||||
"/*path",
|
||||
any(|path: Path<String>| async move { format!("backend: {}", path.0) }),
|
||||
);
|
||||
let backend_server = Server::bind(&"127.0.0.1:0".parse().unwrap())
|
||||
.serve(backend_router.into_make_service());
|
||||
let backend_server =
|
||||
Server::bind("127.0.0.1:0".parse().unwrap()).serve(backend_router.into_make_service());
|
||||
let backend_addr = backend_server.local_addr();
|
||||
let backend_handle = tokio::spawn(async move { backend_server.await.unwrap() });
|
||||
config.backend = format!("http://{}{}", backend_addr, config.backend);
|
||||
let router = super::add_proxy(Router::new(), &config);
|
||||
let server = Server::bind("127.0.0.1:0".parse().unwrap())
|
||||
.serve(router.unwrap().into_make_service());
|
||||
let server =
|
||||
Server::bind("127.0.0.1:0".parse().unwrap()).serve(router.unwrap().into_make_service());
|
||||
let server_addr = server.local_addr();
|
||||
let server_handle = tokio::spawn(async move { server.await.unwrap() });
|
||||
(backend_handle, server_handle, server_addr.to_string())
|
||||
|
||||
Reference in new issue
Block a user