/** * nginx image recipe — static reverse proxy via a generated `nginx.conf`. * * Opt-in via `images.proxy`. HTTP edge on :80; put Cloudflare / ALB / another * TLS terminator in front, or prefer Caddy / Traefik for automatic HTTPS. */ import { APP_PORT } from "../../runtime/types.ts"; import type { ImageRecipe } from "../types.ts"; /** Compose service name for the application container. */ export const NGINX_APP_SERVICE = "app"; /** * Build a minimal nginx.conf — reverse-proxy to the compose `app` service. * * @param opts - Upstream app port on the compose network */ export function buildNginxConf(opts: { readonly appPort?: number } = {}): string { const port = opts.appPort ?? APP_PORT; return [ "# Generated by `oke docker` — edit via compose.override.yml / replace this file.", "events { worker_connections 1024; }", "http {", " upstream oke_app {", ` server ${NGINX_APP_SERVICE}:${port};`, " }", " server {", " listen 80;", " server_name _;", " location / {", " proxy_pass http://oke_app;", " proxy_http_version 1.1;", " proxy_set_header Host $host;", " proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;", " proxy_set_header X-Forwarded-Proto $scheme;", " proxy_set_header Upgrade $http_upgrade;", " proxy_set_header Connection $http_connection;", " }", " }", "}", "", ].join("\n"); } /** nginx reverse proxy. HTTP 80 (TLS via an outer edge or switch to Caddy). */ export const nginx: ImageRecipe = { id: "nginx", port: 80, match: (i) => /nginx/i.test(i), apply: () => ({ volumes: ["./nginx.conf:/etc/nginx/nginx.conf:ro"], healthcheck: { test: ["CMD", "nginx", "-t"], interval: "10s", timeout: "3s", retries: 5, }, }), url: (_s, c) => `http://${c.host}`, };