fix a few CLI errors

This commit is contained in:
Evan Almloff committed 2024-02-16 12:39:36 -06:00
1 parent e745212157
commit 194d90e66f
6 files changed
+15 -14

No files matched your search

+1 -1
View File
@@ -336,7 +336,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()
.nest(&base_path, axum::routing::any_service(router.into())) .route(&base_path, axum::routing::any_service(router.into()))
.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) }
+10 -8
View File
@@ -4,12 +4,13 @@ use dioxus_cli_config::WebProxyConfig;
use anyhow::Context; use 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 axum::body::Body as MyBody; use axum::body::Body as MyBody;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct ProxyClient { struct ProxyClient {
inner: hyper::Client<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>>, inner: Client<hyper_rustls::HttpsConnector<Client::HttpConnector>>,
url: Uri, url: Uri,
} }
@@ -22,7 +23,7 @@ impl ProxyClient {
.enable_http1() .enable_http1()
.build(); .build();
Self { Self {
inner: hyper::Client::builder().build(https), inner: Client::builder().build(https),
url, url,
} }
} }
@@ -98,6 +99,7 @@ mod test {
use super::*; use super::*;
use axum::{extract::Path, Router}; use axum::{extract::Path, Router};
use axum_server::Server;
fn setup_servers( fn setup_servers(
mut config: WebProxyConfig, mut config: WebProxyConfig,
@@ -110,13 +112,13 @@ 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 = axum::Server::bind(&"127.0.0.1:0".parse().unwrap()) let backend_server = Server::bind(&"127.0.0.1:0".parse().unwrap())
.serve(backend_router.into_make_service()); .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 = axum::Server::bind(&"127.0.0.1:0".parse().unwrap()) let server = Server::bind("127.0.0.1:0".parse().unwrap())
.serve(router.unwrap().into_make_service()); .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() });
@@ -132,8 +134,8 @@ mod test {
// So in day to day usage, use `http://localhost:8000/api` instead! // So in day to day usage, use `http://localhost:8000/api` instead!
backend: path, backend: path,
}; };
let (backend_handle, server_handle, server_addr) = setup_servers(config); let (backend_handle, server_handle, server_addr) = setup_servers(config).await;
let resp = hyper::Client::new() let resp = Client::new()
.get(format!("http://{}/api", server_addr).parse().unwrap()) .get(format!("http://{}/api", server_addr).parse().unwrap())
.await .await
.unwrap(); .unwrap();
@@ -145,7 +147,7 @@ mod test {
"backend: /api" "backend: /api"
); );
let resp = hyper::Client::new() let resp = Client::new()
.get(format!("http://{}/api/", server_addr).parse().unwrap()) .get(format!("http://{}/api/", server_addr).parse().unwrap())
.await .await
.unwrap(); .unwrap();
@@ -157,7 +159,7 @@ mod test {
"backend: /api/" "backend: /api/"
); );
let resp = hyper::Client::new() let resp = Client::new()
.get( .get(
format!("http://{}/api/subpath", server_addr) format!("http://{}/api/subpath", server_addr)
.parse() .parse()
@@ -49,7 +49,7 @@ fn main() {
// build our application with some routes // build our application with some routes
let app = Router::new() let app = Router::new()
// Server side render the application, serve static assets, and register server functions // Server side render the application, serve static assets, and register server functions
.serve_dioxus_application("", ServeConfig::builder().build(), || { .serve_dioxus_application(ServeConfig::builder().build(), || {
VirtualDom::new(app) VirtualDom::new(app)
}) })
.layer( .layer(
@@ -12,8 +12,8 @@ async fn main() {
.await .await
.unwrap(); .unwrap();
let _ = PostServerData::register_explicit(); let _ = register_explicit::<PostServerData>();
let _ = GetServerData::register_explicit(); let _ = register_explicit::<GetServerData>();
axum::serve( axum::serve(
listener, listener,
@@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "server")] #[cfg(feature = "server")]
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
pre_cache_static_routes_with_props( pre_cache_static_routes(
&ServeConfig::new_with_router( &ServeConfig::new_with_router(
dioxus_fullstack::router::FullstackRouterConfig::<Route>::default(), dioxus_fullstack::router::FullstackRouterConfig::<Route>::default(),
) )
-1
View File
@@ -23,7 +23,6 @@ server_fn_macro = "^0.6.5"
proc-macro = true proc-macro = true
[features] [features]
actix = ["server_fn_macro/actix"]
axum = ["server_fn_macro/axum"] axum = ["server_fn_macro/axum"]
nightly = ["server_fn_macro/nightly"] nightly = ["server_fn_macro/nightly"]
server = ["server_fn_macro/ssr"] server = ["server_fn_macro/ssr"]