Allow request method restriction on domain (#174)

* add limit_except generator to domain

* revert package-lock.json

* change from limit param to if statement in restrict methods

* add response code input

* fix scss
This commit is contained in:
Yasio
2020-10-15 18:52:41 +02:00
committed by GitHub
parent 5daf54ebde
commit d9d9a1a92a
7 changed files with 344 additions and 1 deletions

View File

@@ -166,6 +166,18 @@ export default (domain, domains, global) => {
serverConfig.push(...securityConf(domains, global));
}
// Restrict Methods
if (Object.keys(domain.restrict).find(k => domain.restrict[k].computed && k !== 'responseCode')) {
const allowedKeys = Object.keys(domain.restrict)
.filter(k => !domain.restrict[k].computed && k !== 'responseCode')
.map(e => e.replace('Method', '').toUpperCase());
serverConfig.push(['# restrict methods', '']);
serverConfig.push([`if ($request_method !~ ^(${allowedKeys.join('|')})$)`, {
'return': `'${domain.restrict.responseCode.computed}'`,
}]);
}
// Access log or error log for domain
if (domain.logging.accessLog.computed || domain.logging.errorLog.computed) {
serverConfig.push(['# logging', '']);