我正在配置 nginx 位置,但我需要在重定向之前运行一个更新 requestBody 的脚本:
这是我的 conf 但是当我部署它时仍然重定向而不更新 requestBody 或返回错误
父级nginx.conf:
// .....
js_import checkScript from /etc/nginx/js/scripts/checkScript.js;
// ....
在 checkScript.js 中:
export default {
rights
}
function rights(r) {
const body = JSON.parse(r.requestBody);
if (body.isAdmin) {
body.rights = ['ADMIN']
} else {
r.return(403, 'Not admin');
}
}
products.http-service.conf :
location /api/data/products/new {
set $gateway_role "dev.yumStore";
set $gateway_realm "yumStore";
auth_request /_tokenExchange;
# check rights and update body
js_content checkScript.rights;
proxy_set_header "Authorization" $gateway_auth_header;
# redirection
proxy_pass $OUTGATEWAY/api/data/products/new;
}
感谢您的帮助!