Created
May 11, 2020 19:27
-
-
Save georgepaoli/724e0c773e91ed15402a5db76197c1d2 to your computer and use it in GitHub Desktop.
Get json field in body request using Lua in NGINX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name localhost; | |
location / { | |
default_type application/json; | |
access_by_lua_block { | |
ngx.req.read_body() | |
local cjson = require "cjson" | |
local body = cjson.decode(ngx.req.get_body_data()) | |
ngx.req.set_header("x-body-token", body.token) | |
} | |
proxy_read_timeout 300; | |
proxy_pass https://postman-echo.com/post; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection keep-alive; | |
proxy_set_header Host $host; | |
proxy_cache_bypass $http_upgrade; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment