Skip to content

Instantly share code, notes, and snippets.

@narate
Created June 6, 2022 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save narate/c3e0a18f966324b0cacded02855b8bc9 to your computer and use it in GitHub Desktop.
Save narate/c3e0a18f966324b0cacded02855b8bc9 to your computer and use it in GitHub Desktop.
Kong Serverless Function
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