Make Proxy Optional Feature

This commit is contained in:
spikecodes
2020-11-23 16:57:37 -08:00
parent 8a488af594
commit b218ec6065
4 changed files with 42 additions and 26 deletions

View File

@@ -2,13 +2,17 @@ use actix_web::{get, web, HttpResponse, Result, client::Client, Error};
#[get("/imageproxy/{url:.*}")]
async fn handler(web::Path(url): web::Path<String>) -> Result<HttpResponse> {
dbg!(&url);
let client = Client::default();
client.get(url)
.send()
.await
.map_err(Error::from)
.and_then(|res| {
Ok(HttpResponse::build(res.status()).streaming(res))
})
if cfg!(feature = "proxy") {
dbg!(&url);
let client = Client::default();
client.get(url)
.send()
.await
.map_err(Error::from)
.and_then(|res| {
Ok(HttpResponse::build(res.status()).streaming(res))
})
} else {
Ok(HttpResponse::Ok().body(""))
}
}