46 lines
793 B
TypeScript
Executable File
46 lines
793 B
TypeScript
Executable File
import { writeFileSync } from "fs"
|
|
import mappings from "./mappings"
|
|
|
|
let caddyfile = `# Caddyfile
|
|
hy-pr.link {
|
|
redir /silicoflare https://silicoflare.dev
|
|
redir /flare https://silicoflare.dev
|
|
}
|
|
|
|
`
|
|
|
|
Object.entries(mappings).map(([key, value]) => {
|
|
|
|
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(":").slice(1).join(":")}
|
|
}
|
|
|
|
`
|
|
} else if (value.startsWith("/")) {
|
|
caddyfile += `${key} {
|
|
root * ${value}
|
|
encode gzip zstd
|
|
try_files {path} /index.html
|
|
file_server
|
|
}
|
|
|
|
`
|
|
} else {
|
|
caddyfile += `${key} {
|
|
reverse_proxy ${value}
|
|
}
|
|
|
|
`
|
|
}
|
|
})
|
|
|
|
writeFileSync("/etc/caddy/Caddyfile", caddyfile)
|