Fix issues on njs and template

This commit is contained in:
Ricardo Katz 2023-09-05 23:03:57 +00:00
parent edaf443ff2
commit 4da8a13614
3 changed files with 13 additions and 7 deletions

View file

@ -130,7 +130,10 @@ func NewPassthroughConfigRequest(data interface{}) (status string, err error) {
return "NOK", err
}
return string(reply), nil
if strings.Contains(string(reply), "NOK") {
return "NOK", fmt.Errorf("fail to reconfigure dynamically")
}
return "OK", nil
}
// GetServerBlock takes an nginx.conf file and a host and tries to find the server block for that host

View file

@ -81,7 +81,7 @@ function configureWithData(configdata, s) {
// Clear method is not working, we should verify with NGX folks
//ngx.shared.passthrough.clear();
ngx.shared.passthrough.set(KEYNAME, JSON.stringify(backends))
ngx.shared.ptbackends.set(KEYNAME, JSON.stringify(backends))
return OK
} catch (e) {
@ -97,7 +97,7 @@ function getBackend(s) {
if (hostname == null || hostname == "undefined" || hostname == "") {
throw("hostname was not provided")
}
let backends = ngx.shared.passthrough.get(KEYNAME)
let backends = ngx.shared.ptbackends.get(KEYNAME)
if (backends == null || backends == "") {
throw('no entry on endpoint map')
}
@ -116,4 +116,4 @@ function getBackend(s) {
}
}
export default {getConfigStatus, configBackends, getBackend};
export default {getConfigStatus, configBackends, getBackend};

View file

@ -37,7 +37,7 @@ load_module /etc/nginx/modules/ngx_http_opentracing_module.so;
load_module /modules_mount/etc/nginx/modules/otel/otel_ngx_module.so;
{{ end }}
load_module modules/ngx_stream_js_module.so;
load_module /etc/nginx/modules/ngx_stream_js_module.so;
daemon off;
@ -761,6 +761,7 @@ http {
}
}
}
}
stream {
@ -837,8 +838,9 @@ stream {
We want this server to be always running
*/}}
js_import njs/passthrough.js;
js_import /etc/nginx/njs/passthrough.js;
js_shared_dict_zone zone=ptbackends:32m type=string;
server {
listen 19090;
js_preread passthrough.configBackends;
@ -847,7 +849,8 @@ stream {
}
{{ if and $all.IsSSLPassthroughEnabled }}
server {
{{ buildSSLPassthroughListener $all }}
# TODO: Remove Hardcode
listen 443;
ssl_preread on;
js_set $ptupstream passthrough.getBackend;
proxy_pass $ptupstream;