char/ngx

git clone https://git.t4t.associates/char/ngx

Charlotte Somv0.2.1: update README and fix serverName types5e3eca8

main
639 B33 linesraw

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.2";

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

const DOMAIN = "a.com";

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

if (import.meta.main) console.log(config.build());
1# ngx
2
3Opinionated nginx config generation for Deno.
4
5## Example
6
7Generate an nginx configuration to permanently redirect some routes from a.com to their new locations at b.com:
8
9```typescript
10import ngx from "jsr:@char/ngx@0.2";
11
12const redirects = {
13  "/a": "https://b.com/new-a",
14  "/b": "https://b.com/b-v2",
15};
16
17const DOMAIN = "a.com";
18
19const config = ngx("server", [
20  [
21    ngx.serverName(DOMAIN),
22    ...ngx.listen(),
23    ...ngx.letsEncrypt(DOMAIN),
24  ],
25  Object.entries(redirects).map(([path, uri]) =>
26    ngx(`location = ${path}`, [
27      `return 301 ${uri}`
28    ])
29  )
30])
31
32if (import.meta.main) console.log(config.build());
33```