Skip to content

Commit 65e4be3

Browse files
committed
chore: use elxir env reading patterns
1 parent fa6341b commit 65e4be3

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

apps/query-service/config/prod.exs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import Config
22

3+
# Mark this as production environment (used by application.ex to skip repo if no DATABASE_URL)
4+
config :query_service_ex, env: :prod
5+
36
# For production, don't forget to configure the url host
47
# to something meaningful, Phoenix uses this information
58
# when generating URLs.
6-
9+
# Note: secret_key_base is set in runtime.exs, using a build-time placeholder here
710
config :query_service_ex, QueryServiceExWeb.Endpoint,
8-
url: [host: System.get_env("PHX_HOST") || "localhost", port: 443, scheme: "https"],
11+
url: [host: "localhost", port: 443, scheme: "https"],
912
http: [
1013
# Enable IPv6 and bind on all interfaces.
11-
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
1214
ip: {0, 0, 0, 0, 0, 0, 0, 0},
13-
port: String.to_integer(System.get_env("PORT") || "3902")
15+
port: 3902
1416
],
15-
secret_key_base: System.fetch_env!("SECRET_KEY_BASE"),
17+
secret_key_base: "build_time_placeholder_will_be_replaced_at_runtime_by_runtime_exs_config",
1618
server: true
1719

18-
# Configure Rust Core backend
20+
# Configure Rust Core backend (defaults, can be overridden in runtime.exs)
1921
config :query_service_ex,
20-
rust_core_url: System.get_env("RUST_CORE_URL") || "http://localhost:3900",
21-
core_ws_url: System.get_env("CORE_WS_URL") || "ws://localhost:3900"
22+
rust_core_url: "http://localhost:3900",
23+
core_ws_url: "ws://localhost:3900"
2224

2325
# Do not print debug messages in production
2426
config :logger, level: :info

apps/query-service/lib/query_service_ex/application.ex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ defmodule QueryServiceEx.Application do
1515
# Initialize ETS cache for projections
1616
ProjectionSync.init_cache()
1717

18-
# In test mode, the Repo is started manually by test_helper.exs after testcontainers
19-
# sets up the database. In other environments, the Repo starts with the application.
20-
repo_children =
21-
if Application.get_env(:query_service_ex, :skip_repo_start, false) do
22-
[]
23-
else
24-
[QueryServiceEx.Repo]
25-
end
18+
# Skip Repo start if:
19+
# 1. Explicitly disabled via config (test mode with testcontainers)
20+
# 2. In prod without DATABASE_URL (container health checks, image testing)
21+
is_prod? = Application.get_env(:query_service_ex, :env) == :prod
22+
no_database_url? = is_nil(System.get_env("DATABASE_URL"))
23+
24+
skip_repo? =
25+
Application.get_env(:query_service_ex, :skip_repo_start, false) ||
26+
(is_prod? and no_database_url?)
27+
28+
repo_children = if skip_repo?, do: [], else: [QueryServiceEx.Repo]
2629

2730
children =
2831
repo_children ++

0 commit comments

Comments
 (0)