Skip to content

Commit

Permalink
Remove use_nginx_wrapper option
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Nov 2, 2023
1 parent 0076796 commit 3a17a40
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 26 deletions.
17 changes: 1 addition & 16 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate tracing;

use crates_io::middleware::normalize_path::normalize_path;
use crates_io::{metrics::LogEncoder, util::errors::AppResult, App};
use std::{fs::File, process::Command, sync::Arc, time::Duration};
use std::{sync::Arc, time::Duration};

use axum::ServiceExt;
use futures_util::future::FutureExt;
Expand Down Expand Up @@ -80,21 +80,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// the test suite :)
info!("Listening at http://{addr}");

// Creating this file tells heroku to tell nginx that the application is ready
// to receive traffic.
if app.config.use_nginx_wrapper {
let path = "/tmp/app-initialized";
info!("Writing to {path}");
File::create(path).unwrap();

// Launch nginx via the Heroku nginx buildpack
// `wait()` is never called on the child process, but it should be okay to leave a zombie
// process around on shutdown when Heroku is tearing down the entire container anyway.
Command::new("./script/start-web.sh")
.spawn()
.expect("Couldn't spawn nginx");
}

// Block the main thread until the server has shutdown
rt.block_on(server)?;

Expand Down
11 changes: 2 additions & 9 deletions src/config/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub struct Server {
pub ip: IpAddr,
pub port: u16,
pub max_blocking_threads: Option<usize>,
pub use_nginx_wrapper: bool,
pub db: DatabasePools,
pub storage: StorageConfig,
pub session_key: cookie::Key,
Expand Down Expand Up @@ -105,20 +104,15 @@ impl Default for Server {
/// This function panics if the Server configuration is invalid.
fn default() -> Self {
let docker = dotenvy::var("DEV_DOCKER").is_ok();

let heroku = dotenvy::var("HEROKU").is_ok();
let use_nginx_wrapper = heroku && dotenvy::var("USE_NGINX").unwrap_or_default() != "n";

let ip = if (heroku && !use_nginx_wrapper) || docker {
let ip = if heroku || docker {
[0, 0, 0, 0].into()
} else {
[127, 0, 0, 1].into()
};

let port = match (use_nginx_wrapper, env_optional("PORT")) {
(false, Some(port)) => port,
_ => 8888,
};
let port = env_optional("PORT").unwrap_or(8888);

let allowed_origins = AllowedOrigins::from_default_env();
let page_offset_ua_blocklist = match env_optional::<String>("WEB_PAGE_OFFSET_UA_BLOCKLIST")
Expand Down Expand Up @@ -189,7 +183,6 @@ impl Default for Server {
ip,
port,
max_blocking_threads,
use_nginx_wrapper,
session_key: cookie::Key::derive_from(env("SESSION_KEY").as_bytes()),
gh_client_id: ClientId::new(env("GH_CLIENT_ID")),
gh_client_secret: ClientSecret::new(env("GH_CLIENT_SECRET")),
Expand Down
1 change: 0 additions & 1 deletion src/tests/util/test_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ fn simple_config() -> config::Server {
ip: [127, 0, 0, 1].into(),
port: 8888,
max_blocking_threads: None,
use_nginx_wrapper: false,
db,
storage,
session_key: cookie::Key::derive_from("test this has to be over 32 bytes long".as_bytes()),
Expand Down

0 comments on commit 3a17a40

Please sign in to comment.