Score:0

How to modify the body response with Nginx and Javascript

ua flag

I have a simple task but it seems hard to find the solution over the internet.

My goal is to modify/alter the response my Nginx proxy is returning to the caller, for example: assuming the following GET http://somehost/somejsom the actual response I got from my Nginx is a Json like this:

{
 "propA": "valueA",
 "propB": "valueB"
}

I need to change the value of "propA" to "valueC", or even simple perform the following replace operation:

replace("\"propA\": \"valueA\"", "\"propA\": \"valueC\"")

Bonus point if I can perform this replace only if the request body contains a specified value.

Score:0
cn flag
Bob

You can rewrite the (HTML) content / body by enabling the nginx ngx_http_sub_module. That will also allow you to do simple string substitution.

A different method is with the nginx_substitutions_filter that also supports regular expressions

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.