Skip to content

Modifying the POST body in onProxyReq #90

Closed
@dvmorris

Description

@dvmorris

Following this recipe: https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/modify-post.md, I expect to be able conditionally modify the POST body based on the proxy path. The encodeURIComponent portion of this script only works with objects that are one level deep.

How do I make this work with any object, no matter how many levels deep it might go, or just bypass the onProxyReq method entirely for other URL's I don't care about?

Setup

  • body-parser: 1.15.1
  • http-proxy-middleware: 0.15.2
  • express: 4.13.4

proxy middleware configuration

const apiProxy = proxyMiddleware('/services', {
  target: config.serverUrl,
  changeOrigin: true,
  pathRewrite: {
    '^/services': ''
  },
  onProxyReq: // just like the recipe linked above, but with a conditional check on proxy path

server mounting

const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use(apiProxy);
app.listen(3000);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions