Files
bunny2realip/src/bunny2realip/core.clj
2025-09-28 08:44:46 +02:00

29 lines
779 B
Clojure

(ns bunny2realip.core
(:require [babashka.http-client :as http]
[cheshire.core :as json]
[clojure.string :as s]
[clojure.string :as str]))
(defonce ip-lists ["https://bunnycdn.com/api/system/edgeserverlist/"
"https://bunnycdn.com/api/system/cdnserverlist/"])
(defonce realip-dest "/etc/nginx/conf.d/bunny.conf")
(defn get-list
[url]
(-> url
http/get
:body
json/parse-string))
(defn format-ips
[ip]
(str "set_real_ip_from " ip ";"))
(defn -main [& args]
(let [ips (set (mapcat get-list ip-lists))
realips (map format-ips (sort ips))]
(as-> realips $
(concat $ ["real_ip_header X-Real-IP;" "real_ip_recursive on;"])
(str/join "\n" $)
(spit realip-dest $))))