diff options
| author | Fuwn <[email protected]> | 2021-05-06 21:18:42 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-06 21:18:42 -0700 |
| commit | 7b5733c7af3ec28a687db713e6d44792dc06142d (patch) | |
| tree | bc0254035c90ce68ac504806b52e1d3977f20899 | |
| parent | refactor(deps): move npm deps to dev deps (diff) | |
| download | api-7b5733c7af3ec28a687db713e6d44792dc06142d.tar.xz api-7b5733c7af3ec28a687db713e6d44792dc06142d.zip | |
fix(utils): conditional authorization header placement
Usefull when deploying with Docker.
| -rw-r--r-- | src/utils.rs | 25 |
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? |