Giter Club home page Giter Club logo

reverse-proxy-demo's Introduction

ReverseProxyDemo

The purpose of this repo is to demonstrate a problem with a NestJS middlware combined with the npm package http-proxy-middlware. There's a corresponding StackOverflow post referring to this repo.

Get apps up and running

  1. Clone the repo
  2. Run npm install
  3. Fire up the Todos API via ng serve todos-api. Run curl http://localhost:8090/api and you should receive a 200 OK response with an array of todos.
  4. Fire up the API Gateway via ng serve api-gateway. Run curl http://localhost:8080/api and you should receive a 200 OK response with a JSON response {"ok":true}.

Re-produce the issue

The following requests are sent to the API Gateway on port 8080 which serves as kind of a reverse proxy for the Todos API which runs on port 8090.

  • Requests made to http://localhost:8080/api/v1/... are reverse-proxied through a global functional middleware which is setup in main.ts.
  • Requests made to http://localhost:8080/api/v2/... are reverse-proxied through a NestJS Middlware which is setup in reverse-proxy.middleware.ts and registered in app.module.ts.

In the following requests you'll see that the GET requests are proxied successfully through both kinds of middlwares. The PUT request, though, is only proxied successfully throug the global functional middlware. Proxying through the Nest JS Middeware fails, the client never receives a response (it's kinda "hanging").

  1. Run curl http://localhost:8080/api/v1/todos-api and you should receive the array of todos.
  2. Run curl http://localhost:8080/api/v2/todos-api and you should also receive the array of todos.
  3. Run curl -X PUT -H "Content-Type: application/json" -d "{\"id\": 1, \"userId\": 1, \"title\": \"delectus aut autem - v1\", \"completed\": true}" http://localhost:8080/api/v1/todos-api/1 and you should receive a 200 OK and the todo should have been updated successfully.
  4. Run curl -X PUT -H "Content-Type: application/json" -d "{\"id\": 1, \"userId\": 1, \"title\": \"delectus aut autem - v2\", \"completed\": true}" http://localhost:8080/api/v2/todos-api/1 and you will never receive a response, the request just keeps "hanging".

reverse-proxy-demo's People

Contributors

bebadt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.