{"_rev":"15-923bc115307e0dcf1ee9f9d4d7101fa8","time":{"created":"2024-12-07T03:48:57.569Z","modified":"2024-12-07T03:48:58.211Z","0.1.0":"2024-12-06T13:13:59.905Z","0.1.1":"2024-12-06T13:20:33.584Z","0.1.2":"2024-12-06T13:46:58.047Z","0.1.3":"2024-12-06T14:05:01.380Z","0.1.4":"2024-12-06T14:18:58.510Z","0.1.5":"2024-12-06T14:25:03.515Z","0.2.0":"2024-12-06T14:43:51.023Z","0.3.0":"2024-12-07T02:52:01.515Z","0.3.1":"2024-12-07T03:48:57.895Z"},"_id":"@dwikyrza/nginx-config-builder","name":"@dwikyrza/nginx-config-builder","dist-tags":{"latest":"0.3.1"},"versions":{"0.3.1":{"name":"@dwikyrza/nginx-config-builder","version":"0.3.1","description":"A TypeScript library for building Nginx configuration files programmatically","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.js"}},"keywords":["nginx","config","builder"],"author":{"name":"Dwiky Rizky Ananditya"},"license":"MIT","devDependencies":{"@types/eslint-config-prettier":"^6.11.3","@typescript-eslint/eslint-plugin":"^8.17.0","@typescript-eslint/parser":"^8.17.0","eslint":"^9.16.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","globals":"^15.13.0","prettier":"^3.4.2","tsup":"^8.3.5","typescript":"^5.7.2"},"repository":{"type":"git","url":"git+https://github.com/kyzsuukii/nginx-config-builder.git"},"bugs":{"url":"https://github.com/kyzsuukii/nginx-config-builder/issues"},"homepage":"https://github.com/kyzsuukii/nginx-config-builder#readme","scripts":{"build":"tsup","test":"echo \"Error: no test specified\" && exit 1","format":"prettier --write \"src/**/*.{ts,tsx}\" \"examples/**/*.{ts,tsx}\"","lint":"eslint . --config eslint.config.mjs","lint:fix":"eslint . --config eslint.config.mjs --fix"},"_id":"@dwikyrza/nginx-config-builder@0.3.1","_integrity":"sha512-VjI4NjlEjgLjAefrxJnO4E/M6VHCcBr5dtV+XSm4w26xNuzer9aBm7l3872TY7zn44/XUdCTRW2HpB6Af21Nfg==","_resolved":"/tmp/4864d7cb55f1617e3246e7595832939a/dwikyrza-nginx-config-builder-0.3.1.tgz","_from":"file:dwikyrza-nginx-config-builder-0.3.1.tgz","_nodeVersion":"20.18.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-VjI4NjlEjgLjAefrxJnO4E/M6VHCcBr5dtV+XSm4w26xNuzer9aBm7l3872TY7zn44/XUdCTRW2HpB6Af21Nfg==","shasum":"1fc6291a2898b8dac60d67387a088c082814d7c4","tarball":"https://registry.npmjs.org/@dwikyrza/nginx-config-builder/-/nginx-config-builder-0.3.1.tgz","fileCount":9,"unpackedSize":317199,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCP7scAp03ybnNF+9txFRfFLGhSkfGRAjmQOxNmeCdtfgIgSWuUETF/J/uRWOEYUPMPlUjrwGVUdEj+72pVZXWgDDo="}]},"_npmUser":{"name":"dwiky.ra","email":"kyzsuki@gmail.com"},"directories":{},"maintainers":[{"name":"dwiky.ra","email":"kyzsuki@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nginx-config-builder_0.3.1_1733543337692_0.2972111485435758"},"_hasShrinkwrap":false}},"maintainers":[{"name":"dwiky.ra","email":"kyzsuki@gmail.com"}],"description":"A TypeScript library for building Nginx configuration files programmatically","homepage":"https://github.com/kyzsuukii/nginx-config-builder#readme","keywords":["nginx","config","builder"],"repository":{"type":"git","url":"git+https://github.com/kyzsuukii/nginx-config-builder.git"},"author":{"name":"Dwiky Rizky Ananditya"},"bugs":{"url":"https://github.com/kyzsuukii/nginx-config-builder/issues"},"license":"MIT","readme":"# Nginx Config Builder\n\nA TypeScript library for building Nginx configuration files programmatically.\n\n## Installation\n\n```bash\nnpm install @dwikyrza/nginx-config-builder\n```\n\n## Usage\n\nThis library provides two main classes for building Nginx configurations:\n\n### NginxConfig\n\n`NginxConfig` is designed for creating complete Nginx configurations, including HTTP, events, and other top-level directives. Use this when you need to generate a full `nginx.conf` file.\n\n```ts\nimport { NginxConfig } from \"@dwikyrza/nginx-config-builder\";\n\nconst config = new NginxConfig();\n\nconfig.user(\"nginx\");\nconfig.workerProcesses(\"auto\");\nconfig.pid(\"/run/nginx.pid\");\n\nconfig\n  .events()\n  .workerConnections(1024)\n  .multiAccept(true)\n  .useEpoll(true)\n  .acceptMutex(true)\n  .acceptMutexDelay(500);\n\nconst http = config.http();\n\nhttp.applyTypedDirectives({\n  keepalive_timeout: 65,\n  sendfile: true,\n  default_type: \"application/octet-stream\",\n  tcp_nopush: true,\n  tcp_nodelay: true,\n});\n\nhttp\n  .clientMaxBodySize(\"10m\")\n  .clientBodyBufferSize(\"128k\")\n  .clientHeaderTimeout(60)\n  .clientBodyTimeout(60)\n  .sendTimeout(60)\n  .gzip(true)\n  .gzipTypes([\n    \"text/plain\",\n    \"text/css\",\n    \"application/json\",\n    \"application/javascript\",\n    \"text/xml\",\n    \"application/xml\",\n  ])\n  .gzipMinLength(\"1000\")\n  .gzipComp(6);\n\nhttp\n  .addUpstream(\"backend_servers\")\n  .server(\"127.0.0.1:8001\")\n  .server(\"127.0.0.1:8002\")\n  .server(\"127.0.0.1:8003\")\n  .leastConn();\n\nconst server = http.addServer(80);\nserver.serverName(\"example.com www.example.com\");\nserver.accessLog(\"/var/log/nginx/access.log\", \"combined\");\nserver.errorLog(\"/var/log/nginx/error.log\", \"warn\");\n\nserver.listen(443, true);\nserver.sslCertificate(\"/etc/nginx/ssl/example.com.crt\");\nserver.sslCertificateKey(\"/etc/nginx/ssl/example.com.key\");\nserver.sslProtocols(\"TLSv1.2\", \"TLSv1.3\");\n\nserver\n  .addLocation(\"/\")\n  .root(\"/var/www/html\")\n  .index(\"index.html\", \"index.htm\")\n  .tryFiles(\"$uri\", \"$uri/\", \"/index.html\");\n\nserver\n  .addLocation(\"/api\")\n  .proxyPass(\"http://backend_servers\")\n  .proxyBuffering(false)\n  .proxySetHeader(\"X-Real-IP\", \"$remote_addr\")\n  .proxySetHeader(\"X-Forwarded-For\", \"$proxy_add_x_forwarded_for\")\n  .proxySetHeader(\"X-Forwarded-Proto\", \"$scheme\")\n  .proxySetHeader(\"Host\", \"$host\");\n\nserver\n  .addLocation(\"/\")\n  .addHeader(\"X-Frame-Options\", \"DENY\")\n  .addHeader(\"X-Content-Type-Options\", \"nosniff\")\n  .addHeader(\"X-XSS-Protection\", \"1; mode=block\")\n  .addHeader(\"Referrer-Policy\", \"strict-origin-when-cross-origin\");\n\nconst output = config.build();\nconsole.log(output);\n```\n\nOutput:\n\n```nginx\nuser nginx;\n\nworker_processes auto;\n\npid /run/nginx.pid;\n\nevents {\n    worker_connections 1024;\n    multi_accept on;\n    use epoll;\n    accept_mutex on;\n    accept_mutex_delay 500ms;\n}\n\nhttp {\n    sendfile on;\n    keepalive_timeout 65;\n    default_type application/octet-stream;\n    tcp_nopush on;\n    tcp_nodelay on;\n\n    client_max_body_size 10m;\n    client_body_buffer_size 128k;\n    client_header_timeout 60;\n    client_body_timeout 60;\n    send_timeout 60;\n    gzip on;\n    gzip_types text/plain text/css application/json application/javascript text/xml application/xml;\n    gzip_min_length 1000;\n    gzip_comp_level 6;\n\n    upstream backend_servers {\n        server 127.0.0.1:8001;\n        server 127.0.0.1:8002;\n        server 127.0.0.1:8003;\n        least_conn;\n    }\n\n    server {\n        listen 80;\n        server_name example.com www.example.com;\n        access_log /var/log/nginx/access.log combined;\n        error_log /var/log/nginx/error.log warn;\n        listen 443 ssl;\n        ssl_certificate /etc/nginx/ssl/example.com.crt;\n        ssl_certificate_key /etc/nginx/ssl/example.com.key;\n        ssl_protocols TLSv1.2 TLSv1.3;\n\n        location  / {\n            root /var/www/html;\n            index index.html index.htm;\n            try_files $uri $uri/ /index.html;\n        }\n\n        location  /api {\n            proxy_pass http://backend_servers;\n            proxy_buffering off;\n            proxy_set_header X-Real-IP $remote_addr;\n            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n            proxy_set_header X-Forwarded-Proto $scheme;\n            proxy_set_header Host $host;\n        }\n\n        location  / {\n            add_header X-Frame-Options DENY;\n            add_header X-Content-Type-Options nosniff;\n            add_header X-XSS-Protection 1; mode=block;\n            add_header Referrer-Policy strict-origin-when-cross-origin;\n        }\n    }\n}\n```\n\n### SiteConfig\n\n`SiteConfig` is focused on creating individual server configurations. It's ideal for generating site-specific configurations that will be included in the main Nginx configuration. Use this when you want to create configurations for individual sites in `/etc/nginx/sites-available/`.\n\n```ts\nimport { SiteConfig } from \"@dwikyrza/nginx-config-builder\";\n\nconst config = new SiteConfig();\n\nconst site = config.addServer(80);\n\nsite.serverName(\"example.com\");\nsite.addLocation(\"/\").root(\"/var/www/html\").index(\"index.html\", \"index.htm\");\nsite\n  .addLocation(\"/api\")\n  .proxyPass(\"http://localhost:3000\")\n  .proxyBuffering(false)\n  .proxySetHeader(\"X-Real-IP\", \"$remote_addr\")\n  .proxySetHeader(\"X-Forwarded-For\", \"$proxy_add_x_forwarded_for\")\n  .proxySetHeader(\"X-Forwarded-Proto\", \"https\");\n\nconst output = config.build();\nconsole.log(output);\n```\n\nOutput:\n\n```nginx\nserver {\n    listen 80;\n\n    server_name example.com;\n\n    location / {\n        root /var/www/html;\n        index index.html index.htm;\n    }\n\n    location /api {\n        proxy_pass http://localhost:3000;\n        proxy_buffering off;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header X-Forwarded-Proto https;\n    }\n}\n```\n\n## Key Differences\n\n- **NginxConfig**: Creates complete Nginx configurations including:\n\n  - Top-level directives (user, worker_processes, pid)\n  - Events block configuration\n  - HTTP block with multiple servers\n  - Upstream and map configurations\n  - Suitable for generating main `nginx.conf`\n\n- **SiteConfig**: Focuses on server-level configuration:\n  - Single server block configuration\n  - No top-level directives or HTTP block\n  - Ideal for site-specific configurations\n  - Perfect for `/etc/nginx/sites-available/` configurations\n\n## Examples\n\nFor more examples, please refer to the [examples](https://github.com/kyzsuukii/nginx-config-builder/tree/master/examples) folder.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","readmeFilename":"README.md"}