Compare commits
No commits in common. "263778400c7728e4d1296fd09269873e521f0a97" and "1888dbacc52832dbc507128856b85b0ab0ea5e17" have entirely different histories.
263778400c
...
1888dbacc5
30
README.md
30
README.md
|
@ -1,31 +1,3 @@
|
||||||
# ngx
|
# ngx
|
||||||
|
|
||||||
Opinionated nginx config generation for Deno.
|
Opinionated nginx config generation in 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());
|
|
||||||
```
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"name": "@char/ngx",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"exports": "./ngx.ts"
|
|
||||||
}
|
|
4
ngx.ts
4
ngx.ts
|
@ -1,5 +1,6 @@
|
||||||
const NGX_VERSION = "0.1.0";
|
const NGX_VERSION = "0.1";
|
||||||
|
|
||||||
|
// #region Implementation
|
||||||
type ConfigNode = ConfigStatement | ConfigBlock | ConfigBreak | ConfigFile;
|
type ConfigNode = ConfigStatement | ConfigBlock | ConfigBreak | ConfigFile;
|
||||||
|
|
||||||
class ConfigBuildable {
|
class ConfigBuildable {
|
||||||
|
@ -88,6 +89,7 @@ function conform(looseNode: LooseConfigNode): ConfigNode[] {
|
||||||
}
|
}
|
||||||
return [looseNode];
|
return [looseNode];
|
||||||
}
|
}
|
||||||
|
// #endregion
|
||||||
|
|
||||||
export function ngx(value?: string, children?: LooseConfigNode[]): ConfigNode {
|
export function ngx(value?: string, children?: LooseConfigNode[]): ConfigNode {
|
||||||
const hasValue = value !== undefined && value !== "";
|
const hasValue = value !== undefined && value !== "";
|
||||||
|
|
Loading…
Reference in New Issue