Proxy or Stub with NGINX
In case it is useful for someone else: here is another way to have a proxy stubbing some of the incoming requests.
The external tests are in shell directly with curl
. My initial need was to stub some graphQL
requests so don’t be surprised to see mostly POST
requests and a stubbing decision based on the incoming body.
It was a good opportunity to look at the njs scripting language of NGINX and play with it. The Magic Number containing the folder of the script should probably be extracted.
In the real usage of this tool I use several json data files with a filtering mechanism to choose the appropriate stub data depending on the incoming request. I have played before with a single json file with Node or Java, but this time I preferred separate files for each request given the sometimes huge returned payload.
Enjoy 🙂
Leave a Reply