Skip to content

Commit

Permalink
fix default template & interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
j4ys0n committed Jul 12, 2024
1 parent 389c95c commit aa6c3f5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "llm-proxy",
"version": "1.1.4",
"version": "1.1.5",
"description": "Manages Nginx for reverse proxy to multiple LLMs, with TLS & Bearer Auth tokens",
"main": "dist/index.js",
"scripts": {
Expand Down
24 changes: 17 additions & 7 deletions src/controllers/nginx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ export class NginxController {
}

private async updateConfig(req: Request, res: Response): Promise<void> {
const { success, message } = await this.nginxManager.updateConfig(req.body)
const status = success ? 200 : 500
res.status(status).json({ success, message })
if (req.body != null && req.body.config != null) {
const newConfig = req.body.config
const { success, message } = await this.nginxManager.updateConfig(newConfig)
const status = success ? 200 : 500
res.status(status).json({ success, message })
} else {
res.status(400).json({ success: false, message: 'Invalid request body' })
}
}

private async getConfig(req: Request, res: Response): Promise<void> {
Expand All @@ -55,11 +60,16 @@ export class NginxController {
}

private async writeDefaultConfig(req: Request, res: Response): Promise<void> {
const { success, message } = await this.nginxManager.writeDefaultTemplate()
if (success) {
res.json({ success, message: 'Default config written successfully' })
if (req.body != null && req.body.domain != null) {
const domain = req.body.domain
const { success, message } = await this.nginxManager.writeDefaultTemplate(domain)
if (success) {
res.json({ success, message: 'Default config written successfully' })
} else {
res.status(500).json({ success, message })
}
} else {
res.status(500).json({ success, message })
res.status(400).json({ success: false, message: 'Invalid request body' })
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/static/nginx-server-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ server {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Add-Control-Allow-Methods' 'GET, POST';

server_name {{ domainName }};
server_name {{domainName}};
server_tokens off;

real_ip_header X-Forwarded-For;

ssl_certificate /etc/letsencrypt/live/{{ domainName }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ domainName }}/privkey.pem;
ssl_certificate /etc/letsencrypt/live/{{domainName}}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{domainName}}/privkey.pem;
# include /etc/letsencrypt/options-ssl-nginx.conf;
# ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

Expand Down
5 changes: 3 additions & 2 deletions src/utils/nginx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ export class NginxManager {
return this.putFile(this.configPath, newConfig)
}

async writeDefaultTemplate(): Promise<NginxResponse> {
async writeDefaultTemplate(domain: string): Promise<NginxResponse> {
const templateContent = await readFile(CONFIG_TEMPLATE_PATH, 'utf-8')
return this.putFile(this.configPath, templateContent)
const content = templateContent.replace(/{{domainName}}/g, domain)
return this.putFile(this.configPath, content)
}

async getConfig(): Promise<NginxConfigResponse> {
Expand Down

0 comments on commit aa6c3f5

Please sign in to comment.