0.0.4 • Published 6 months ago

nginx-builder v0.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

Simple Nginx configuration builder - NodeJS

Heading

Config:

new NginxBuilder({
    outputPath: path.resolve(__dirname, "config"),
    fileName: "docker.webserver.conf",
    apps: [
        {
            name: "app1",
            serverName: "app1.domain.local app1.domain.ch",
            port: 80,
            proxy: [
                {
                    locationPath:' /api/',
                    host: "host.docker.internal",
                    path:'/api/',
                    port: 8003,
                },
                {
                    locationPath:' /api/docs/',
                    host: "host.docker.internal",
                    path:'/swagger/',
                    port: 8003,
                },
                {
                    locationPath: "^/api/app/(?<endpoint>.+)$",
                    path: "/api",
                    host: "$endpoint.app.external.ch",
                    options:{
                        locationPrefix:'~',
                        https: true,
                        rewrite:'^/api/app/(.+) /api break',
                    }

                }
            ],
            locations:[
                {
                    locationPath:'/',
                    path: "/var/www/app1",
                }
            ]
        },
        {
            name: "app2",
            serverName: "app2.domain.local app2.domain.ch",
            port: 80,
            proxy: [
                {
                    locationPath:' /api/',
                    host: "host.docker.internal",
                    path:'/api/',
                    port: 8004,
                },
                {
                    locationPath:' /api/docs/',
                    host: "host.docker.internal",
                    path:'/swagger/',
                    port: 8004,
                },
            ],
            locations:[
                {
                    locationPath:'/',
                    path: "/var/www/app2",
                }
            ]
        },
    ],
})

Result:

server
{
	listen 80;
	server_name app1.domain.local app1.domain.ch;
	location /
	{
		root /var/www/app1;
		try_files $uri $uri/ /index.html?$query_string;
	}
	location /api/
	{
		proxy_pass http://host.docker.internal:8003/api/;
	}
	location /api/docs/
	{
		proxy_pass http://host.docker.internal:8003/swagger/;
	}
	location ~ ^/api/app/(?<endpoint>.+)$ {
		rewrite ^/api/app/(.+) /api break;
		proxy_pass https://$endpoint.app.external.ch/api;
	}
}

server
{
	listen 80;
	server_name app2.domain.local app2.domain.ch;
	location /
	{
		root /var/www/app2;
		try_files $uri $uri/ /index.html?$query_string;
	}
	location /api/
	{
		proxy_pass http://host.docker.internal:8004/api/;
	}
	location /api/docs/
	{
		proxy_pass http://host.docker.internal:8004/swagger/;
	}
}

Installation:

npm i --save nginx-builder

How to use:

import { NginxBuilder } from 'nginx-builder'

const nginxBuilder = new NginxBuilder(yourConfig);

nginxBuilder.saveToFile(nginxBuilder.build(),{
    encoding:  'utf8',
    indent: '\t',
    newLineSeparator: '\n',
    maxStatementLength: 80, // if statement is longer than that it will be splitted into multiple lines
})
0.0.4

6 months ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago