Skip to content

Commit 210da49

Browse files
committed
add cidr groups
1 parent 7c96d08 commit 210da49

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

example.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PORT=3000
1+
PORT=8080
22
TARGET_URLS=http://localhost:1234/v1
33
JWT_SECRET=your-jwt-secret-key-here
44
AUTH_USERNAME=admin

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "llm-proxy",
3-
"version": "1.1.5",
3+
"version": "1.2.0",
44
"description": "Manages Nginx for reverse proxy to multiple LLMs, with TLS & Bearer Auth tokens",
55
"main": "dist/index.js",
66
"scripts": {
@@ -18,7 +18,8 @@
1818
"openai",
1919
"certificate",
2020
"bearer auth",
21-
"tls"
21+
"tls",
22+
"ai"
2223
],
2324
"author": "Jayson Jacobs",
2425
"license": "Apache-2.0",

src/controllers/nginx.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ export class NginxController {
1313
}
1414

1515
public registerRoutes(): void {
16-
this.app.post('/nginx/reload', ...this.requestHandlers, this.reloadNginx.bind(this))
16+
this.app.get('/nginx/reload', ...this.requestHandlers, this.reloadNginx.bind(this))
1717
this.app.post('/nginx/config/update', ...this.requestHandlers, this.updateConfig.bind(this))
1818
this.app.get('/nginx/config/get', ...this.requestHandlers, this.getConfig.bind(this))
1919
this.app.get('/nginx/config/get-default', ...this.requestHandlers, this.getDefaultConfig.bind(this))
20-
this.app.get('/nginx/config/write-default', ...this.requestHandlers, this.writeDefaultConfig.bind(this))
20+
this.app.post('/nginx/config/write-default', ...this.requestHandlers, this.writeDefaultConfig.bind(this))
2121
this.app.post('/nginx/certificates/obtain', ...this.requestHandlers, this.obtainCertificates.bind(this))
2222
this.app.get('/nginx/certificates/renew', ...this.requestHandlers, this.renewCertificates.bind(this))
2323
log('info', 'NginxController initialized')
@@ -60,13 +60,17 @@ export class NginxController {
6060
}
6161

6262
private async writeDefaultConfig(req: Request, res: Response): Promise<void> {
63-
if (req.body != null && req.body.domain != null) {
64-
const domain = req.body.domain
65-
const { success, message } = await this.nginxManager.writeDefaultTemplate(domain)
66-
if (success) {
67-
res.json({ success, message: 'Default config written successfully' })
63+
if (req.body != null && req.body.domain != null && req.body.cidrGroups != null) {
64+
const { domain, cidrGroups } = req.body
65+
if (Array.isArray(cidrGroups) && typeof domain === 'string') {
66+
const { success, message } = await this.nginxManager.writeDefaultTemplate(domain, cidrGroups)
67+
if (success) {
68+
res.json({ success, message: 'Default config written successfully' })
69+
} else {
70+
res.status(500).json({ success, message })
71+
}
6872
} else {
69-
res.status(500).json({ success, message })
73+
res.status(400).json({ success: false, message: 'Invalid request body' })
7074
}
7175
} else {
7276
res.status(400).json({ success: false, message: 'Invalid request body' })

src/static/nginx-server-template.conf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ server {
4444
proxy_buffering off;
4545
client_max_body_size 0;
4646
proxy_read_timeout 36000s;
47-
allow 10.1.0.0/16;
48-
allow 10.6.0.0/24;
49-
allow 10.9.9.0/24;
50-
allow 10.99.10.0/24;
47+
{{allowedIPs}}
5148
deny all;
5249
}
5350

src/utils/nginx.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ export class NginxManager {
6262
return this.putFile(this.configPath, newConfig)
6363
}
6464

65-
async writeDefaultTemplate(domain: string): Promise<NginxResponse> {
65+
async writeDefaultTemplate(domain: string, cidrGroups: string[]): Promise<NginxResponse> {
6666
const templateContent = await readFile(CONFIG_TEMPLATE_PATH, 'utf-8')
67-
const content = templateContent.replace(/{{domainName}}/g, domain)
67+
const allowedIPs = cidrGroups.map((g) => ` allow ${g};\n`).reduce((acc, curr) => acc + curr, '')
68+
const content = templateContent
69+
.replace(/{{domainName}}/g, domain)
70+
.replace(/{{allowedIPs}}/g, allowedIPs)
6871
return this.putFile(this.configPath, content)
6972
}
7073

0 commit comments

Comments
 (0)