From 71388e36beea551e9aa74fb9974bea4eaaac94bd Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 8 Aug 2024 11:58:17 +0700 Subject: [PATCH] Nginx free add fix --- src/executor/nginx.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/executor/nginx.js b/src/executor/nginx.js index aafe545..1d31994 100644 --- a/src/executor/nginx.js +++ b/src/executor/nginx.js @@ -155,11 +155,16 @@ class NginxExecutor { } expandLocation(node, info.config); if (info.free) { - if (!Array.isArray(node.location) || node.location.length == 0 || node.location[0]._value != '/') { + if (!Array.isArray(node.location)) { node._add('location', '/') - node.location[node.location.length - 1]._add('if', `($http_referer !~ "^https?://${info.dom}")`); - node.location[node.location.length - 1].if[0]._add('rewrite', '^ /deceptive.html last'); } + let idx = node.location.findIndex(x => x._value == '/'); + if (idx == -1) { + node._add('location', '/') + idx = node.location.length - 1; + } + node.location[idx]._add('if', `($http_referer !~ "^https?://${info.dom}")`); + node.location[idx].if[0]._add('rewrite', '^ /deceptive.html last'); let loc = node._add('location', '= /deceptive.html', []); loc.location[loc.location.length - 1]._add('root', '/usr/local/share/www') loc.location[loc.location.length - 1]._add('internal')