From 3ee29889649c2820e494c51c8bd81b9385a45d62 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sat, 19 Jan 2019 15:41:51 +0100 Subject: [PATCH] fix(core): update --- test/test.ts | 2 ++ ts/interfaces/hostconfig.ts | 1 + ts/smartnginx.classes.nginxhost.ts | 6 +++++- ts/smartnginx.classes.smartnginx.ts | 3 ++- ts/smartnginx.snippets.ts | 8 ++++---- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/test/test.ts b/test/test.ts index 0fb73d3..c08b336 100644 --- a/test/test.ts +++ b/test/test.ts @@ -19,12 +19,14 @@ tap.test(`should produce an instance of NginxConfig`, async () => { testNginxZone01 = new smartnginx.NginxHost(testSmartNginx, { hostName: 'test100.bleu.de', destination: '192.192.192.191', + destinationPort: 3000, privateKey: 'some private', publicKey: 'some public' }); testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, { hostName: 'test102.bleu.de', destination: '192.192.192.192', + destinationPort: 3050, privateKey: 'some private', publicKey: 'some public' }); diff --git a/ts/interfaces/hostconfig.ts b/ts/interfaces/hostconfig.ts index 21f53e9..9ac4263 100644 --- a/ts/interfaces/hostconfig.ts +++ b/ts/interfaces/hostconfig.ts @@ -1,6 +1,7 @@ export interface IHostConfig { hostName: string; destination: string; + destinationPort: number; privateKey: string; publicKey: string; } diff --git a/ts/smartnginx.classes.nginxhost.ts b/ts/smartnginx.classes.nginxhost.ts index 372c782..b28fd9a 100644 --- a/ts/smartnginx.classes.nginxhost.ts +++ b/ts/smartnginx.classes.nginxhost.ts @@ -21,6 +21,7 @@ export class NginxHost implements IHostConfig { public hostName: string; // the host name e.g. domain name public destination: string; + public destinationPort: number; public configString: string; // the actual host config file as string public privateKey: string; public publicKey: string; @@ -29,7 +30,7 @@ export class NginxHost implements IHostConfig { this.smartnginxInstance = smartnginxInstanceArg; this.hostName = optionsArg.hostName; this.destination = optionsArg.destination; - this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination); + this.destinationPort = optionsArg.destinationPort; this.privateKey = optionsArg.privateKey; this.publicKey = optionsArg.publicKey; } @@ -42,7 +43,10 @@ export class NginxHost implements IHostConfig { const filePathConfig = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.conf`); const filePathPrivate = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.private.pem`); const filePathPublic = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.public.pem`); + + // writeConfig + this.configString = snippets.getHostConfigString(this.hostName, this.destination, this.destinationPort); plugins.smartfile.memory.toFsSync(this.configString, filePathConfig); // write ssl diff --git a/ts/smartnginx.classes.smartnginx.ts b/ts/smartnginx.classes.smartnginx.ts index 5fddcd1..fa1e7ad 100644 --- a/ts/smartnginx.classes.smartnginx.ts +++ b/ts/smartnginx.classes.smartnginx.ts @@ -78,7 +78,8 @@ export class SmartNginx { await this.deployedHosts.forEach(async deployedHostArg => { if ( hostCandidateArg.hostName === deployedHostArg.hostName && - hostCandidateArg.destination === deployedHostArg.destination + hostCandidateArg.destination === deployedHostArg.destination && + hostCandidateArg.destinationPort === deployedHostArg.destinationPort ) { hostCounter++; foundHost = true; diff --git a/ts/smartnginx.snippets.ts b/ts/smartnginx.snippets.ts index 0e06292..c7cb00b 100644 --- a/ts/smartnginx.snippets.ts +++ b/ts/smartnginx.snippets.ts @@ -1,7 +1,7 @@ import * as plugins from './smartnginx.plugins'; import * as paths from './smartnginx.paths'; export let getBaseConfigString = () => { - let baseConfig = plugins.smartstring.indent.normalize(` + const baseConfig = plugins.smartstring.indent.normalize(` user www-data; worker_processes auto; pid /run/nginx/nginx.pid; @@ -71,8 +71,8 @@ export let getBaseConfigString = () => { return baseConfig; }; -export let getHostConfigString = (hostNameArg: string, destinationIpArg: string) => { - let hostConfig = plugins.smartstring.indent.normalize(` +export let getHostConfigString = (hostNameArg: string, destinationIpArg: string, portArg = 80) => { + const hostConfig = plugins.smartstring.indent.normalize(` upstream ${hostNameArg} { keepalive 100; server ${destinationIpArg}; @@ -101,7 +101,7 @@ export let getHostConfigString = (hostNameArg: string, destinationIpArg: string) proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass http://${hostNameArg}; + proxy_pass http://${hostNameArg}:${portArg}; } } `);