diff options
| author | mo khan <mo@mokhan.ca> | 2025-05-30 12:40:38 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-05-30 12:40:38 -0600 |
| commit | 463c259bd41f20d5811b028e8045f3de3effe097 (patch) | |
| tree | f669fa26ccbb4e46c146fcb924d093ce8b9bb4a4 | |
| parent | f59105ea06171e090b22b37f74d861ccd781a6ed (diff) | |
feat: parse BIND_ADDR env variable
| -rwxr-xr-x | bin/test | 11 | ||||
| -rw-r--r-- | src/main.rs | 7 |
2 files changed, 14 insertions, 4 deletions
@@ -9,10 +9,15 @@ gemfile do gem "net-hippie", "~> 1.0" end -pid = Process.spawn("mise exec -- cargo run") +$bind_addr = ENV.fetch("BIND_ADDR", "127.0.0.1:7878") + +pid = Process.spawn({ + "BIND_ADDR" => $bind_addr +}, "mise exec -- cargo run") sleep 1 at_exit do + Process.kill('SIGTERM', pid) system("killall sts") end @@ -22,7 +27,7 @@ class ServerTest < Minitest::Test attr_reader :base_url, :client def setup - @base_url = "http://127.0.0.1:7878" + @base_url = "http://#{$bind_addr}" @client = Net::Hippie::Client.new end @@ -40,7 +45,7 @@ class ServerTest < Minitest::Test def test_metadata response = client.get(base_url + "/.well-known/oauth-authorization-server") assert_equal "200", response.code - # assert_equal "application/json", response["Content-Type"] + assert_equal "application/json", response["Content-Type"] end # /token - Token endpoint https://datatracker.ietf.org/doc/html/rfc8693#section-2.3 diff --git a/src/main.rs b/src/main.rs index d7633b4..442bfe2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,12 @@ use sts::http::Server; fn main() { - let server = Server::new(String::from("127.0.0.1:7878")); + let bind_addr: String = match std::env::var("BIND_ADDR") { + Ok(val) => val, + Err(_) => String::from("127.0.0.1:7878"), + }; + + let server = Server::new(bind_addr); server.start(); } |
