Add example to README

main
Charlotte Som 2024-02-29 21:27:49 +00:00
parent 2c91d30b1d
commit 263778400c
1 changed files with 28 additions and 0 deletions

View File

@ -1,3 +1,31 @@
# 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:
```typescript
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());
```