2024-01-05 15:32:14 +00:00
|
|
|
# ngx
|
2023-08-09 06:56:34 +00:00
|
|
|
|
2024-02-29 21:20:44 +00:00
|
|
|
Opinionated nginx config generation for Deno.
|
2024-02-29 21:27:49 +00:00
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
Generate an nginx configuration to permanently redirect some routes from a.com to their new locations at b.com:
|
|
|
|
|
|
|
|
```typescript
|
2024-11-27 03:38:46 +00:00
|
|
|
import ngx from "jsr:@char/ngx@0.2";
|
2024-02-29 21:27:49 +00:00
|
|
|
|
|
|
|
const redirects = {
|
|
|
|
"/a": "https://b.com/new-a",
|
|
|
|
"/b": "https://b.com/b-v2",
|
|
|
|
};
|
|
|
|
|
2024-11-27 03:38:46 +00:00
|
|
|
const DOMAIN = "a.com";
|
|
|
|
|
2024-02-29 21:27:49 +00:00
|
|
|
const config = ngx("server", [
|
|
|
|
[
|
2024-11-27 03:38:46 +00:00
|
|
|
ngx.serverName(DOMAIN),
|
2024-02-29 21:27:49 +00:00
|
|
|
...ngx.listen(),
|
2024-11-27 03:38:46 +00:00
|
|
|
...ngx.letsEncrypt(DOMAIN),
|
2024-02-29 21:27:49 +00:00
|
|
|
],
|
|
|
|
Object.entries(redirects).map(([path, uri]) =>
|
|
|
|
ngx(`location = ${path}`, [
|
|
|
|
`return 301 ${uri}`
|
|
|
|
])
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
|
|
|
if (import.meta.main) console.log(config.build());
|
|
|
|
```
|