|
1 | 1 | #![warn(clippy::all, rust_2018_idioms)]
|
2 | 2 |
|
3 |
| -use cargo_registry::{metrics::LogEncoder, util::errors::AppResult, App, Env}; |
| 3 | +use cargo_registry::{env_optional, metrics::LogEncoder, util::errors::AppResult, App, Env}; |
4 | 4 | use std::{env, fs::File, process::Command, sync::Arc, time::Duration};
|
5 | 5 |
|
6 | 6 | use conduit_hyper::Service;
|
@@ -54,24 +54,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
54 | 54 | } else {
|
55 | 55 | [127, 0, 0, 1]
|
56 | 56 | };
|
57 |
| - let port = if heroku { |
58 |
| - 8888 |
59 |
| - } else { |
60 |
| - dotenv::var("PORT") |
61 |
| - .ok() |
62 |
| - .and_then(|s| s.parse().ok()) |
63 |
| - .unwrap_or(8888) |
| 57 | + let port = match (heroku, env_optional("PORT")) { |
| 58 | + (false, Some(port)) => port, |
| 59 | + _ => 8888, |
64 | 60 | };
|
| 61 | + |
65 | 62 | let threads = dotenv::var("SERVER_THREADS")
|
66 | 63 | .map(|s| s.parse().expect("SERVER_THREADS was not a valid number"))
|
67 |
| - .unwrap_or_else(|_| { |
68 |
| - if env == Env::Development { |
69 |
| - 5 |
70 |
| - } else { |
71 |
| - // A large default because this can be easily changed via env and in production we |
72 |
| - // want the logging middleware to accurately record the start time. |
73 |
| - 500 |
74 |
| - } |
| 64 | + .unwrap_or_else(|_| match env { |
| 65 | + Env::Development => 5, |
| 66 | + // A large default because this can be easily changed via env and in production we |
| 67 | + // want the logging middleware to accurately record the start time. |
| 68 | + _ => 500, |
75 | 69 | });
|
76 | 70 |
|
77 | 71 | println!("Booting with a hyper based server");
|
|
0 commit comments