fix(core): update

This commit is contained in:
2019-04-10 19:03:17 +02:00
parent 82f3b4bd7d
commit e5b75014af
7 changed files with 95 additions and 24 deletions

View File

@ -5,10 +5,16 @@ import { NginxHost } from './smartnginx.classes.nginxhost';
import { NginxProcess } from './smartnginx.classes.nginxprocess';
import { IHostConfig } from './interfaces/hostconfig';
export interface ISmartNginxContructorOptions {
logger?: plugins.smartlog.Smartlog;
defaultProxyUrl: string;
}
/**
* main class that manages a NginxInstance
*/
export class SmartNginx {
public options: ISmartNginxContructorOptions;
public logger: plugins.smartlog.Smartlog;
// the objectmaps
@ -16,9 +22,10 @@ export class SmartNginx {
private hostCandidates = new plugins.lik.Objectmap<NginxHost>();
public nginxProcess: NginxProcess = new NginxProcess(this);
constructor(optionsArg: { logger?: plugins.smartlog.Smartlog }) {
optionsArg.logger
? (this.logger = optionsArg.logger)
constructor(optionsArg: ISmartNginxContructorOptions) {
this.options = optionsArg;
this.options.logger
? (this.logger = this.options.logger)
: (this.logger = plugins.smartlog.defaultLogger);
}
@ -108,7 +115,12 @@ export class SmartNginx {
// write base config
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigDirPath);
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(this.options.defaultProxyUrl), paths.nginxConfFile);
// write standard self signed certificate
const selfsignedCert = plugins.selfsigned.generate([{ name: 'commonName', value: 'selfsigned.git.zone' }], { days: 365});
plugins.smartfile.memory.toFsSync(selfsignedCert.private, plugins.path.join(paths.nginxConfigDirPath, './default.private.pem'));
plugins.smartfile.memory.toFsSync(selfsignedCert.public, plugins.path.join(paths.nginxConfigDirPath, './default.public.pem'));
// deploy hosts
plugins.smartfile.fs.ensureEmptyDirSync(paths.nginxHostDirPath);

View File

@ -13,3 +13,10 @@ import * as smartstring from '@pushrocks/smartstring';
import * as smartunique from '@pushrocks/smartunique';
export { lik, smartlog, smartpromise, smartshell, smartfile, smartstring, smartunique };
// thirdparty scope
import * as selfsigned from 'selfsigned';
export {
selfsigned
};

View File

@ -1,6 +1,6 @@
import * as plugins from './smartnginx.plugins';
import * as paths from './smartnginx.paths';
export let getBaseConfigString = () => {
export let getBaseConfigString = (defaultProxy: string) => {
const baseConfig = plugins.smartstring.indent.normalize(`
user www-data;
worker_processes auto;
@ -63,6 +63,31 @@ export let getBaseConfigString = () => {
# Virtual Host Configs
##
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 default_server;
rewrite ^ ${defaultProxy} permanent;
}
server {
listen *:443 ssl default_server;
ssl_certificate ${paths.nginxHostDirPath}/default.public.pem;
ssl_certificate_key ${paths.nginxHostDirPath}/default.private.pem;
location / {
proxy_http_version 1.1;
proxy_buffering off;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_next_upstream error timeout http_404 http_429 http_500 http_502;
proxy_next_upstream_tries 5;
proxy_pass ${defaultProxy};
}
}
include ${paths.nginxHostDirPath}/*.conf;
include /etc/nginx/sites-enabled/*;
}