Compare commits

...

14 Commits

Author SHA1 Message Date
33833fbc6c 2.0.23 2019-01-19 10:59:25 +01:00
97b5678fe4 fix(core): update 2019-01-19 10:59:24 +01:00
9b96984413 2.0.22 2019-01-19 03:21:27 +01:00
0de412b842 fix(core): update 2019-01-19 03:21:27 +01:00
64bcce9e23 2.0.21 2019-01-19 03:04:38 +01:00
390812ec33 fix(core): update 2019-01-19 03:04:38 +01:00
a672bb920f 2.0.20 2019-01-19 02:46:41 +01:00
c3fabb6107 fix(core): update 2019-01-19 02:46:41 +01:00
b4ebdbae47 2.0.19 2019-01-19 02:44:52 +01:00
c55d2dcf10 fix(core): update 2019-01-19 02:44:52 +01:00
7274d5ea8a 2.0.18 2019-01-19 02:25:35 +01:00
1ec733c2a9 fix(core): update 2019-01-19 02:25:34 +01:00
3ef14d8ac7 2.0.17 2019-01-18 01:33:02 +01:00
f332bf95fe fix(core): update 2019-01-18 01:33:01 +01:00
5 changed files with 18 additions and 11 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartnginx", "name": "@pushrocks/smartnginx",
"version": "2.0.16", "version": "2.0.23",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartnginx", "name": "@pushrocks/smartnginx",
"version": "2.0.16", "version": "2.0.23",
"private": false, "private": false,
"description": "control nginx from node, TypeScript ready", "description": "control nginx from node, TypeScript ready",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -40,6 +40,12 @@ tap.test('.deploy() should deploy a config from an instance', async () => {
await testSmartNginx.deploy(); await testSmartNginx.deploy();
}); });
tap.test('should not redeploy', async () => {
testSmartNginx.addHostCandidate(testNginxZone01);
testSmartNginx.addHostCandidate(testNginxZone02);
await testSmartNginx.deploy();
});
tap.test('.stop() should end the process', async () => { tap.test('.stop() should end the process', async () => {
testSmartNginx.nginxProcess.stop(); testSmartNginx.nginxProcess.stop();
}); });

View File

@ -70,12 +70,12 @@ export class SmartNginx {
* check wether there has been a diverging host configuration * check wether there has been a diverging host configuration
* this function will only redeploy the nginx configuration in case there has been a change * this function will only redeploy the nginx configuration in case there has been a change
*/ */
private areHostsDiverged(): boolean { private async areHostsDiverged(): Promise<boolean> {
let hostCounter = 0; let hostCounter = 0;
let unfoundHosts = 0; let unfoundHosts = 0;
this.hostCandidates.forEach(hostCandidateArg => { await this.hostCandidates.forEach(async hostCandidateArg => {
let foundHost = false; let foundHost = false;
this.deployedHosts.forEach(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
@ -89,7 +89,7 @@ export class SmartNginx {
} }
}); });
return ( return (
this.deployedHosts.getArray.length !== this.hostCandidates.getArray().length || this.deployedHosts.getArray().length !== this.hostCandidates.getArray().length ||
hostCounter !== this.deployedHosts.getArray().length || hostCounter !== this.deployedHosts.getArray().length ||
unfoundHosts !== 0 unfoundHosts !== 0
); );
@ -99,7 +99,7 @@ export class SmartNginx {
* deploy the current stack and restart nginx * deploy the current stack and restart nginx
*/ */
public async deploy() { public async deploy() {
if (this.areHostsDiverged()) { if (await this.areHostsDiverged()) {
this.logger.log('ok', `hosts have diverged, trigger config deployment and nginx reload!`); this.logger.log('ok', `hosts have diverged, trigger config deployment and nginx reload!`);
this.deployedHosts.wipe(); this.deployedHosts.wipe();
this.deployedHosts.addArray(this.hostCandidates.getArray()); this.deployedHosts.addArray(this.hostCandidates.getArray());

View File

@ -74,10 +74,14 @@ export let getBaseConfigString = () => {
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string) => { export let getHostConfigString = (hostNameArg: string, destinationIpArg: string) => {
let hostConfig = plugins.smartstring.indent.normalize(` let hostConfig = plugins.smartstring.indent.normalize(`
upstream ${hostNameArg} { upstream ${hostNameArg} {
keepalive 100;
server ${destinationIpArg}; server ${destinationIpArg};
} }
server { server {
# The keepalive parameter sets the maximum number of idle keepalive connections
# to upstream servers that are preserved in the cache of each worker process. When
# this number is exceeded, the least recently used connections are closed.
listen *:80 ; listen *:80 ;
server_name ${hostNameArg}; server_name ${hostNameArg};
rewrite ^ https://${hostNameArg}$request_uri? permanent; rewrite ^ https://${hostNameArg}$request_uri? permanent;
@ -88,17 +92,14 @@ export let getHostConfigString = (hostNameArg: string, destinationIpArg: string)
server_name ${hostNameArg}; server_name ${hostNameArg};
ssl_certificate ${paths.nginxHostDirPath}/${hostNameArg}.public.pem; ssl_certificate ${paths.nginxHostDirPath}/${hostNameArg}.public.pem;
ssl_certificate_key ${paths.nginxHostDirPath}/${hostNameArg}.private.pem; ssl_certificate_key ${paths.nginxHostDirPath}/${hostNameArg}.private.pem;
location / { location / {
proxy_http_version 1.1;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
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};
} }
location ~ /\.git {
deny all;
}
} }
`); `);
return hostConfig; return hostConfig;