From 6a8acee69ae5a285bf59cd840596f3476a65e75c Mon Sep 17 00:00:00 2001 From: "me@rodrigorodriguez.com" Date: Sat, 19 Oct 2024 23:36:02 -0300 Subject: [PATCH] new(all); ROUTER. --- src/app.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index 67b20482..fa597e26 100644 --- a/src/app.ts +++ b/src/app.ts @@ -263,14 +263,13 @@ export class GBServer { GBServer.globals.webDavServer = await GBCoreService.createWebDavServer(minInstances); // Parse the ROUTE from the .env file + const routeConfig = process.env.ROUTER.split(';').reduce((acc, entry) => { const [domain, port] = entry.split(':'); acc[domain] = port; return acc; }, {}); - // Proxy setup - const proxy = httpProxy.createProxyServer({}); server.all('*', async (req, res, next) => { const host = req.headers.host.startsWith('www.') ? req.headers.host.substring(4) : req.headers.host; @@ -295,6 +294,21 @@ export class GBServer { } else { GBLogEx.info(0, `Host request: ${host}`); + let key = Path.join(process.env.CERT_PATH, `${host}.key.pem`); + let cert = Path.join(process.env.CERT_PATH, `${host}.certificate.pem`); + + // Proxy setup + const proxy = httpProxy.createProxyServer({ + target: { + host: 'localhost', + port: routeConfig[host] + }, + ssl: { + key: await fs.readFile( key, 'utf8'), + cert: await fs.readFile(cert, 'utf8') + } + }); + // If the domain is in routeConfig, proxy to the corresponding local service if (routeConfig[host]) { const target = `http://localhost:${routeConfig[host]}`; @@ -388,6 +402,7 @@ export class GBServer { passphrase: process.env[certPassphraseEnv], pfx: await fs.readFile(process.env[certPfxEnv]) }; + httpsServer.addContext(process.env[certDomainEnv], options); } else { break;