fix(core): update
This commit is contained in:
parent
221f1f6237
commit
3ee2988964
@ -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'
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
export interface IHostConfig {
|
||||
hostName: string;
|
||||
destination: string;
|
||||
destinationPort: number;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
Loading…
Reference in New Issue
Block a user