-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63c6165
commit 69b5cab
Showing
6 changed files
with
94 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use axum::{ | ||
extract::{Request, State}, | ||
http::{StatusCode, Uri}, | ||
response::{IntoResponse, Response}, | ||
}; | ||
|
||
use crate::settings::Settings; | ||
use crate::state::HttpClient; | ||
|
||
pub async fn handler( | ||
State(client): State<HttpClient>, | ||
State(settings): State<Settings>, | ||
mut req: Request, | ||
) -> Result<Response, StatusCode> { | ||
let path = req.uri().path(); | ||
let path_query = req | ||
.uri() | ||
.path_and_query() | ||
.map(|v| v.as_str()) | ||
.unwrap_or(path); | ||
let uri = format!( | ||
"http://{}:{}{}", | ||
settings.proxy.host, settings.proxy.port, path_query | ||
); | ||
|
||
*req.uri_mut() = Uri::try_from(uri).unwrap(); | ||
|
||
Ok(client | ||
.request(req) | ||
.await | ||
.map_err(|_| StatusCode::BAD_REQUEST)? | ||
.into_response()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use axum::{body::Body, extract::FromRef}; | ||
use baffao_core::oauth::OAuthClient; | ||
use hyper_util::client::legacy::connect::HttpConnector; | ||
|
||
use crate::settings::Settings; | ||
|
||
pub type HttpClient = hyper_util::client::legacy::Client<HttpConnector, Body>; | ||
|
||
#[derive(Clone)] | ||
pub struct AppState { | ||
pub client: HttpClient, | ||
pub oauth_client: OAuthClient, | ||
pub settings: Settings, | ||
} | ||
|
||
impl FromRef<AppState> for OAuthClient { | ||
fn from_ref(state: &AppState) -> Self { | ||
state.oauth_client.clone() | ||
} | ||
} | ||
|
||
impl FromRef<AppState> for Settings { | ||
fn from_ref(state: &AppState) -> Self { | ||
state.settings.clone() | ||
} | ||
} | ||
|
||
impl FromRef<AppState> for HttpClient { | ||
fn from_ref(state: &AppState) -> Self { | ||
state.client.clone() | ||
} | ||
} |