I am trying to replace an Id within my request_uri before passing it on via proxy_pass.The Id is replaced within a javascript function
js_set $replacedId http.replaceId;
location ~* v1\/relay-(?<givenId>.*?)(?=\/)
{
rewrite <givenId> $replacedId break;
}
I want to keep the rest so input URL v1/relay-123456/logs/blabla should be translated to v1/relay-7890/logs/blabla during proxy_pass
CodePudding user response:
In case, ID is only numbers:
(?<=relay-)\d ?(?=\/)
In case, ID is any character:
(?<=relay-). ?(?=\/)
let regex = /(?<=relay-)\d ?(?=\/)/;
let url = 'v1/relay-123456/logs/blabla';
let newUrl = url.replace(regex, '7890');
console.log(newUrl);
