Fix proxy (#2108)
This commit is contained in:
1 parent
d8942a255b
commit
10d361a44e
3 files changed
+36
-13
No files matched your search
@@ -65,16 +65,43 @@ pub fn add_proxy(mut router: Router, proxy: &WebProxyConfig) -> Result<Router> {
|
|||||||
|
|
||||||
let client = ProxyClient::new(url);
|
let client = ProxyClient::new(url);
|
||||||
|
|
||||||
|
let method_router = any(move |mut req: Request<MyBody>| async move {
|
||||||
|
// Prevent request loops
|
||||||
|
if req.headers().get("x-proxied-by-dioxus").is_some() {
|
||||||
|
return Err((
|
||||||
|
StatusCode::NOT_FOUND,
|
||||||
|
"API is sharing a loopback with the dev server. Try setting a different port on the API config."
|
||||||
|
.to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
req.headers_mut().insert(
|
||||||
|
"x-proxied-by-dioxus",
|
||||||
|
"true".parse().expect("header value is valid"),
|
||||||
|
);
|
||||||
|
|
||||||
|
client
|
||||||
|
.send(req)
|
||||||
|
.await
|
||||||
|
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))
|
||||||
|
});
|
||||||
|
|
||||||
|
// api/*path
|
||||||
router = router.route(
|
router = router.route(
|
||||||
// Always remove trailing /'s so that the exact route
|
&format!("/{}/*path", trimmed_path.trim_end_matches('/')),
|
||||||
// matches.
|
method_router.clone(),
|
||||||
&format!("/*{}", trimmed_path.trim_end_matches('/')),
|
);
|
||||||
any(move |req: Request<MyBody>| async move {
|
|
||||||
client
|
// /api/
|
||||||
.send(req)
|
router = router.route(
|
||||||
.await
|
&format!("/{}/", trimmed_path.trim_end_matches('/')),
|
||||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))
|
method_router.clone(),
|
||||||
}),
|
);
|
||||||
|
|
||||||
|
// /api
|
||||||
|
router = router.route(
|
||||||
|
&format!("/{}", trimmed_path.trim_end_matches('/')),
|
||||||
|
method_router,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(router)
|
Ok(router)
|
||||||
|
|||||||
@@ -71,9 +71,6 @@ pub fn connect(mut callback: impl FnMut(HotReloadMsg) + Send + 'static) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let Ok(template) = serde_json::from_str(Box::leak(buf.into_boxed_str())) else {
|
let Ok(template) = serde_json::from_str(Box::leak(buf.into_boxed_str())) else {
|
||||||
eprintln!(
|
|
||||||
"Could not parse hot reloading message - make sure your client is up to date"
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use core::panic;
|
|
||||||
use dioxus_html::prelude::{EvalError, EvalProvider, Evaluator};
|
use dioxus_html::prelude::{EvalError, EvalProvider, Evaluator};
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use generational_box::{AnyStorage, GenerationalBox, UnsyncStorage};
|
use generational_box::{AnyStorage, GenerationalBox, UnsyncStorage};
|
||||||
|
|||||||
Reference in new issue
Block a user