Compare commits

...

2 commits

Author SHA1 Message Date
263778400c Add example to README 2024-02-29 21:27:49 +00:00
2c91d30b1d Prepare for jsr publication 2024-02-29 21:20:44 +00:00
3 changed files with 35 additions and 4 deletions

View file

@ -1,3 +1,31 @@
# ngx
Opinionated nginx config generation in Deno.
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());
```

5
deno.json Normal file
View file

@ -0,0 +1,5 @@
{
"name": "@char/ngx",
"version": "0.1.0",
"exports": "./ngx.ts"
}

4
ngx.ts
View file

@ -1,6 +1,5 @@
const NGX_VERSION = "0.1";
const NGX_VERSION = "0.1.0";
// #region Implementation
type ConfigNode = ConfigStatement | ConfigBlock | ConfigBreak | ConfigFile;
class ConfigBuildable {
@ -89,7 +88,6 @@ function conform(looseNode: LooseConfigNode): ConfigNode[] {
}
return [looseNode];
}
// #endregion
export function ngx(value?: string, children?: LooseConfigNode[]): ConfigNode {
const hasValue = value !== undefined && value !== "";