fix(core): update

This commit is contained in:
Philipp Kunz 2019-01-19 15:41:51 +01:00
parent 221f1f6237
commit 3ee2988964
5 changed files with 14 additions and 6 deletions

View File

@ -19,12 +19,14 @@ tap.test(`should produce an instance of NginxConfig`, async () => {
testNginxZone01 = new smartnginx.NginxHost(testSmartNginx, { testNginxZone01 = new smartnginx.NginxHost(testSmartNginx, {
hostName: 'test100.bleu.de', hostName: 'test100.bleu.de',
destination: '192.192.192.191', destination: '192.192.192.191',
destinationPort: 3000,
privateKey: 'some private', privateKey: 'some private',
publicKey: 'some public' publicKey: 'some public'
}); });
testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, { testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, {
hostName: 'test102.bleu.de', hostName: 'test102.bleu.de',
destination: '192.192.192.192', destination: '192.192.192.192',
destinationPort: 3050,
privateKey: 'some private', privateKey: 'some private',
publicKey: 'some public' publicKey: 'some public'
}); });

View File

@ -1,6 +1,7 @@
export interface IHostConfig { export interface IHostConfig {
hostName: string; hostName: string;
destination: string; destination: string;
destinationPort: number;
privateKey: string; privateKey: string;
publicKey: string; publicKey: string;
} }

View File

@ -21,6 +21,7 @@ export class NginxHost implements IHostConfig {
public hostName: string; // the host name e.g. domain name public hostName: string; // the host name e.g. domain name
public destination: string; public destination: string;
public destinationPort: number;
public configString: string; // the actual host config file as string public configString: string; // the actual host config file as string
public privateKey: string; public privateKey: string;
public publicKey: string; public publicKey: string;
@ -29,7 +30,7 @@ export class NginxHost implements IHostConfig {
this.smartnginxInstance = smartnginxInstanceArg; this.smartnginxInstance = smartnginxInstanceArg;
this.hostName = optionsArg.hostName; this.hostName = optionsArg.hostName;
this.destination = optionsArg.destination; this.destination = optionsArg.destination;
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination); this.destinationPort = optionsArg.destinationPort;
this.privateKey = optionsArg.privateKey; this.privateKey = optionsArg.privateKey;
this.publicKey = optionsArg.publicKey; this.publicKey = optionsArg.publicKey;
} }
@ -42,7 +43,10 @@ export class NginxHost implements IHostConfig {
const filePathConfig = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.conf`); const filePathConfig = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.conf`);
const filePathPrivate = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.private.pem`); const filePathPrivate = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.private.pem`);
const filePathPublic = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.public.pem`); const filePathPublic = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.public.pem`);
// writeConfig // writeConfig
this.configString = snippets.getHostConfigString(this.hostName, this.destination, this.destinationPort);
plugins.smartfile.memory.toFsSync(this.configString, filePathConfig); plugins.smartfile.memory.toFsSync(this.configString, filePathConfig);
// write ssl // write ssl

View File

@ -78,7 +78,8 @@ export class SmartNginx {
await this.deployedHosts.forEach(async deployedHostArg => { await this.deployedHosts.forEach(async deployedHostArg => {
if ( if (
hostCandidateArg.hostName === deployedHostArg.hostName && hostCandidateArg.hostName === deployedHostArg.hostName &&
hostCandidateArg.destination === deployedHostArg.destination hostCandidateArg.destination === deployedHostArg.destination &&
hostCandidateArg.destinationPort === deployedHostArg.destinationPort
) { ) {
hostCounter++; hostCounter++;
foundHost = true; foundHost = true;

View File

@ -1,7 +1,7 @@
import * as plugins from './smartnginx.plugins'; import * as plugins from './smartnginx.plugins';
import * as paths from './smartnginx.paths'; import * as paths from './smartnginx.paths';
export let getBaseConfigString = () => { export let getBaseConfigString = () => {
let baseConfig = plugins.smartstring.indent.normalize(` const baseConfig = plugins.smartstring.indent.normalize(`
user www-data; user www-data;
worker_processes auto; worker_processes auto;
pid /run/nginx/nginx.pid; pid /run/nginx/nginx.pid;
@ -71,8 +71,8 @@ export let getBaseConfigString = () => {
return baseConfig; return baseConfig;
}; };
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string) => { export let getHostConfigString = (hostNameArg: string, destinationIpArg: string, portArg = 80) => {
let hostConfig = plugins.smartstring.indent.normalize(` const hostConfig = plugins.smartstring.indent.normalize(`
upstream ${hostNameArg} { upstream ${hostNameArg} {
keepalive 100; keepalive 100;
server ${destinationIpArg}; 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-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://${hostNameArg}; proxy_pass http://${hostNameArg}:${portArg};
} }
} }
`); `);