deno nginx config generator
Find a file
2024-11-27 05:34:18 +02:00
.editorconfig Initial commit 2023-08-09 07:56:34 +01:00
deno.json v0.2: new http2 syntax, drop write(..), add serverName(..) 2024-11-27 05:34:18 +02:00
ngx.ts v0.2: new http2 syntax, drop write(..), add serverName(..) 2024-11-27 05:34:18 +02:00
README.md Add example to README 2024-02-29 21:27:49 +00:00

ngx

Opinionated nginx config generation for Deno.

Example

Generate an nginx configuration to permanently redirect some routes from a.com to their new locations at b.com:

import ngx from "jsr:@char/ngx@0.1";

const redirects = {
  "/a": "https://b.com/new-a",
  "/b": "https://b.com/b-v2",
};

const config = ngx("server", [
  [
    "server_name a.com",
    ...ngx.listen(),
    ...ngx.letsEncrypt("a.com"),
  ],
  Object.entries(redirects).map(([path, uri]) =>
    ngx(`location = ${path}`, [
      `return 301 ${uri}`
    ])
  )
])

if (import.meta.main) console.log(config.build());