mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-02 01:01:20 +00:00
Proxy pictrs healthz endpoint (#5224)
This commit is contained in:
parent
ba3d574d92
commit
bb26a701bc
2 changed files with 24 additions and 1 deletions
|
@ -41,6 +41,9 @@ afterAll(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Upload image and delete it", async () => {
|
test("Upload image and delete it", async () => {
|
||||||
|
const healthz = await fetch(alphaUrl + "/pictrs/healthz");
|
||||||
|
expect(healthz.status).toBe(200);
|
||||||
|
|
||||||
// Before running this test, you need to delete all previous images in the DB
|
// Before running this test, you need to delete all previous images in the DB
|
||||||
await deleteAllImages(alpha);
|
await deleteAllImages(alpha);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,8 @@ pub fn config(
|
||||||
)
|
)
|
||||||
// This has optional query params: /image/{filename}?format=jpg&thumbnail=256
|
// This has optional query params: /image/{filename}?format=jpg&thumbnail=256
|
||||||
.service(web::resource("/pictrs/image/{filename}").route(web::get().to(full_res)))
|
.service(web::resource("/pictrs/image/{filename}").route(web::get().to(full_res)))
|
||||||
.service(web::resource("/pictrs/image/delete/{token}/{filename}").route(web::get().to(delete)));
|
.service(web::resource("/pictrs/image/delete/{token}/{filename}").route(web::get().to(delete)))
|
||||||
|
.service(web::resource("/pictrs/healthz").route(web::get().to(healthz)));
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ProcessUrl {
|
trait ProcessUrl {
|
||||||
|
@ -250,6 +251,25 @@ async fn delete(
|
||||||
Ok(HttpResponse::build(convert_status(res.status())).body(BodyStream::new(res.bytes_stream())))
|
Ok(HttpResponse::build(convert_status(res.status())).body(BodyStream::new(res.bytes_stream())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn healthz(
|
||||||
|
req: HttpRequest,
|
||||||
|
client: web::Data<ClientWithMiddleware>,
|
||||||
|
context: web::Data<LemmyContext>,
|
||||||
|
) -> LemmyResult<HttpResponse> {
|
||||||
|
let pictrs_config = context.settings().pictrs_config()?;
|
||||||
|
let url = format!("{}healthz", pictrs_config.url);
|
||||||
|
|
||||||
|
let mut client_req = adapt_request(&req, &client, url);
|
||||||
|
|
||||||
|
if let Some(addr) = req.head().peer_addr {
|
||||||
|
client_req = client_req.header("X-Forwarded-For", addr.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = client_req.send().await?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::build(convert_status(res.status())).body(BodyStream::new(res.bytes_stream())))
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn image_proxy(
|
pub async fn image_proxy(
|
||||||
Query(params): Query<ImageProxyParams>,
|
Query(params): Query<ImageProxyParams>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
|
|
Loading…
Reference in a new issue