From 187135be4257425cd554d56d04ec222d4ca72168 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Sat, 29 Jun 2024 20:48:03 -0300 Subject: [PATCH] Dynamically update proxy config --- src/daemon.cr | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/daemon.cr b/src/daemon.cr index 11419e4..1073197 100644 --- a/src/daemon.cr +++ b/src/daemon.cr @@ -1,6 +1,8 @@ require "docr" require "kemal" +current_config = "" + get "/" do "Updating routing" # Get all the funkos, create routes for them all @@ -14,6 +16,8 @@ get "/" do funkos << names[0][7..] } + funkos.sort! + proxy_config = %( Port 8888 Listen 0.0.0.0 @@ -24,8 +28,13 @@ ReverseMagic Yes ReversePath "/admin/" "http://127.0.0.1:3000/" ) + funkos.map { |funko| %(ReversePath "/faaso/#{funko}/" "http://#{funko}:3000/") }.join("\n") - File.open("tinyproxy.conf", "w") do |file| - file << proxy_config + if current_config != proxy_config + File.open("tinyproxy.conf", "w") do |file| + file << proxy_config + end + # Reload config + Process.run(command: "/usr/bin/killall", args: ["-USR1", "tinyproxy"]) + current_config = proxy_config end proxy_config end