aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-06 21:18:42 -0700
committerFuwn <[email protected]>2021-05-06 21:18:42 -0700
commit6850b73fc0f57ebd3417a4a4b5277ec89ae4fc69 (patch)
tree8e84e9ed69e52ad2c10c90555f639459b4574f7d
parentrefactor(deps): move npm deps to dev deps (diff)
downloadapi-worker-6850b73fc0f57ebd3417a4a4b5277ec89ae4fc69.tar.xz
api-worker-6850b73fc0f57ebd3417a4a4b5277ec89ae4fc69.zip
fix(utils): conditional authorization header placement
Usefull when deploying with Docker.
-rw-r--r--src/utils.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/utils.rs b/src/utils.rs
index ac1b51d..3d40e7c 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -7,17 +7,22 @@ use crate::{
};
pub async fn github_api() -> Result<GitHubAPIResponse, Box<dyn std::error::Error>> {
+ let mut client = actix_web::client::Client::new()
+ .get(GITHUB_API_ENDPOINT)
+ .header("User-Agent", USER_AGENT);
+
+ if std::env::var("GITHUB_TOKEN").is_ok() {
+ client = client.header(
+ "Authorization",
+ format!(
+ "token {}",
+ std::env::var("GITHUB_TOKEN").unwrap_or_else(|_| "Null".to_string())
+ ),
+ );
+ }
+
Ok(
- actix_web::client::Client::new()
- .get(GITHUB_API_ENDPOINT)
- .header("User-Agent", USER_AGENT)
- .header(
- "Authorization",
- format!(
- "token {}",
- std::env::var("GITHUB_TOKEN").unwrap_or_else(|_| "Null".to_string())
- ),
- )
+ client
.timeout(std::time::Duration::from_secs(60))
.send()
.await?