From 263778400c7728e4d1296fd09269873e521f0a97 Mon Sep 17 00:00:00 2001 From: Charlotte Som Date: Thu, 29 Feb 2024 21:27:49 +0000 Subject: [PATCH] Add example to README --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 9436b0c..399d49d 100644 --- a/README.md +++ b/README.md @@ -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()); +```