Created
June 6, 2022 08:56
-
-
Save narate/c3e0a18f966324b0cacded02855b8bc9 to your computer and use it in GitHub Desktop.
Kong Serverless Function
This file contains 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
local kong = kong | |
local re = ngx.re | |
local headers = kong.response.get_headers() | |
local content_type = headers["Content-Type"] | |
local supported_content_type = "(html|json|xml|plain|css)" | |
local function transform_body(body, old, new) | |
return body:gsub(old, new) | |
end | |
if re.match(content_type, supported_content_type) then | |
local body = kong.response.get_raw_body() | |
if body then | |
local old = "http://127.0.0.1/" | |
local new = "http://localhost/" | |
return kong.response.set_raw_body(transform_body(body, old, new)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment