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
commit7b5733c7af3ec28a687db713e6d44792dc06142d (patch)
treebc0254035c90ce68ac504806b52e1d3977f20899
parentrefactor(deps): move npm deps to dev deps (diff)
downloadapi-7b5733c7af3ec28a687db713e6d44792dc06142d.tar.xz
api-7b5733c7af3ec28a687db713e6d44792dc06142d.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?