Skip to content

Commit 06a0e60

Browse files
authored
Merge pull request #5 from j4ys0n/nginx-config
take domains as input obtainCerts
2 parents 1ff0a6d + 80d2ca7 commit 06a0e60

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "llm-proxy",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Manages Nginx for reverse proxy to multiple LLMs, with TLS & Bearer Auth tokens",
55
"main": "dist/index.js",
66
"scripts": {

src/controllers/nginx.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class NginxController {
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))
2020
this.app.get('/nginx/config/write-default', ...this.requestHandlers, this.writeDefaultConfig.bind(this))
21-
this.app.get('/nginx/certificates/obtain', ...this.requestHandlers, this.obtainCertificates.bind(this))
21+
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')
2424
}
@@ -64,9 +64,14 @@ export class NginxController {
6464
}
6565

6666
private async obtainCertificates(req: Request, res: Response): Promise<void> {
67-
const { success, message } = await this.nginxManager.obtainCertificates(true)
68-
const status = success ? 200 : 500
69-
res.status(status).json({ success, message })
67+
if (req.body != null && req.body.domains != null && Array.isArray(req.body.domains)) {
68+
const domains = req.body.domains
69+
const { success, message } = await this.nginxManager.obtainCertificates(domains, true)
70+
const status = success ? 200 : 500
71+
res.status(status).json({ success, message })
72+
} else {
73+
res.status(400).json({ success: false, message: 'Invalid request body' })
74+
}
7075
}
7176

7277
private async renewCertificates(req: Request, res: Response): Promise<void> {

src/utils/nginx.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ const CONFIG_TEMPLATE_PATH = join(__dirname, '../static/nginx-server-template.co
2121

2222
export class NginxManager {
2323
private configPath: string
24-
private domains: string[]
24+
// private domains: string[]
2525

2626
constructor(configPath: string = '/etc/nginx/conf.d/server.conf', domains: string[] = []) {
2727
this.configPath = configPath
28-
this.domains = domains
28+
// this.domains = domains
2929
}
3030

3131
async start(): Promise<NginxResponse> {
@@ -105,8 +105,8 @@ export class NginxManager {
105105
return { success, config, message }
106106
}
107107

108-
async obtainCertificates(cloudflare?: boolean): Promise<NginxResponse> {
109-
const domainArgs = this.domains.map((domain) => `-d ${domain}`).join(' ')
108+
async obtainCertificates(domains: string[] = [], cloudflare?: boolean): Promise<NginxResponse> {
109+
const domainArgs = domains.map((domain) => `-d ${domain}`).join(' ')
110110
let message: string | undefined
111111
let success = false
112112
const cloudflareFlags = cloudflare

0 commit comments

Comments
 (0)