From 42577243b1f8a1e3caddfe41054bc457c03b3049 Mon Sep 17 00:00:00 2001 From: Suraj B M Date: Thu, 6 Aug 2026 12:51:50 +0530 Subject: [PATCH] feat: refactor caddie to use external mappings and add example mappings --- .gitignore | 1 + caddie.ts | 82 +++++++++------------------------------------ mappings.example.ts | 15 +++++++++ 3 files changed, 32 insertions(+), 66 deletions(-) create mode 100644 .gitignore create mode 100644 mappings.example.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92e1fcc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +mappings.ts \ No newline at end of file diff --git a/caddie.ts b/caddie.ts index 8506f3c..d632011 100755 --- a/caddie.ts +++ b/caddie.ts @@ -1,80 +1,30 @@ import { writeFileSync } from "fs" - -const mappings = { - // portfolio - "blog.silicoflare.dev": "http://localhost:2368", - - // mini-services - "yamtrack.hy-pr.link": "http://localhost:9002", - "todo.hy-pr.link": "http://localhost:9001", - "affine.hy-pr.link": "http://localhost:9005", - "affine-nyx.hy-pr.link": "http://localhost:9005", - "pin.hy-pr.link": "http://localhost:9007", - "dl-api.hy-pr.link": "http://localhost:9011", - "dl.hy-pr.link": "http://localhost:9012", - "pics.hy-pr.link": "http://localhost:9013", - "books.hy-pr.link": "http://localhost:9014", - "nametag.hy-pr.link": "http://localhost:9015", - "rss.hy-pr.link": "http://localhost:8080", - - // mega-services - "git.hy-pr.link": "http://localhost:9100", - "ntfy.hy-pr.link": "http://localhost:9101", - "chat.hy-pr.link": "http://localhost:9102", - "dav.hy-pr.link": "http://localhost:9103", - "files.hy-pr.link": "http://localhost:9104", - "ytrewq.hy-pr.link": "http://localhost:9105", - "pocketbase.hy-pr.link": "http://localhost:8090", - "immich.hy-pr.link": "http://localhost:2283", - "dash.hy-pr.link": "http://localhost:3026", - - // other - "webhook.hy-pr.link": "http://localhost:8000", - "docs.hy-pr.link": "http://localhost:10000", - - // statics - "chef.hy-pr.link": "http://100.64.0.3:8100", - "it-tools.hy-pr.link": "http://100.64.0.3:8101", - "vert.hy-pr.link": "http://100.64.0.3:8103", - "pdf.hy-pr.link": "http://100.64.0.3:8104", - - //sites - "bash.hy-pr.link": "/opt/sites/bash", - "stardew.hy-pr.link": "/opt/sites/stardew", - "predictor.stardew.hy-pr.link": "/opt/sites/stardew-predictor", - "checkup.stardew.hy-pr.link": "/opt/sites/stardew-checkup", - "planner.stardew.hy-pr.link": "/opt/sites/crop_planner", - "helper.stardew.hy-pr.link": "/opt/sites/stardew-fair-helper", -} +import mappings from "./mappings" let caddyfile = `# Caddyfile -http://103.126.231.26 { - redir https://silicoflare.dev{uri} -} - -https://103.126.231.26 { - redir https://silicoflare.dev{uri} -} - hy-pr.link { redir /silicoflare https://silicoflare.dev redir /flare https://silicoflare.dev } -ssh.hy-pr.link { - header Content-Type text/plain - respond "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINt3OrGyuZkH+NliwamlZJPFJsgSF4O2+V149EUhtq3l silicoflare.dev\n" 200 -} - -ssh.silicoflare.dev { - header Content-Type text/plain - respond "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINt3OrGyuZkH+NliwamlZJPFJsgSF4O2+V149EUhtq3l silicoflare.dev\n" 200 -} - ` Object.entries(mappings).map(([key, value]) => { - if (value.startsWith("/")) { + + if (value.startsWith("key:")) { + caddyfile += `${key} { + header Content-Type text/plain + respond "${value.split(":")[1]}\n" 200 +} + +` + } else if (value.startsWith("redir:")) { + caddyfile += `${key} { + redir ${value.split(":")[1]} +} + +` + } else if (value.startsWith("/")) { caddyfile += `${key} { root * ${value} encode gzip zstd diff --git a/mappings.example.ts b/mappings.example.ts new file mode 100644 index 0000000..729d6a9 --- /dev/null +++ b/mappings.example.ts @@ -0,0 +1,15 @@ +const mappings = { + // redirects + "http://ip": "redir:https://example.com{uri}", + + // reverse proxies + "example.com": "http://localhost:8080", + + // static files + "foo.example.com": "/opt/sites/foo", + + // keys + "ssh.example.com": "key:ssh-ed25519 qwerty1234567890 example.com", +} + +export default mappings; \ No newline at end of file