sin0/ip-checker: make curl ip.ny4.dev work

This commit is contained in:
Guanran Wang 2024-11-22 19:39:24 +08:00
parent 766bca73d0
commit 0613aab83f
Signed by: nyancat
GPG key ID: 91F97D9ED12639CF

View file

@ -51,14 +51,36 @@ in
systemd.services."caddy".serviceConfig.SupplementaryGroups = [ "ip-checker" ];
# HACK: this disables automatic https redirection for every VirtualHost
# to make `curl ip.ny4.dev` work
services.caddy.settings.apps.http.servers.srv0 = {
automatic_https.disable_redirects = true;
listen = [ ":80" ];
};
services.caddy.settings.apps.http.servers.srv0.routes = lib.singleton {
match = lib.singleton { host = [ "ip.ny4.dev" ]; };
handle = lib.singleton {
handler = "subroute";
routes = [
# TODO: make `curl ip.ny4.dev` work
{
match = [ { path = [ "/api/v1/*" ]; } ];
match = lib.singleton {
header_regexp."User-Agent".pattern = "^curl/.*";
path = [ "/" ];
};
handle = [
{
handler = "rewrite";
uri = "/api/v1/ip";
}
{
handler = "reverse_proxy";
upstreams = lib.singleton { dial = "unix//run/ip-checker/ip-checker.sock"; };
}
];
}
{
match = lib.singleton { path = [ "/api/v1/*" ]; };
handle = lib.singleton {
handler = "reverse_proxy";
upstreams = lib.singleton { dial = "unix//run/ip-checker/ip-checker.sock"; };