Skip to content

Instantly share code, notes, and snippets.

@ZengineChris
Last active August 29, 2015 14:16
Show Gist options
  • Save ZengineChris/f10090e2c8f52037d09f to your computer and use it in GitHub Desktop.
Save ZengineChris/f10090e2c8f52037d09f to your computer and use it in GitHub Desktop.
Fix a error for the use of the http-proxy and the body parser for express. Without the "connect-restreamer" the post request is not piped correct to the proxy. Add the "connect-restreamer" as middleware behind the body parser fix the issue.
var express = require('express');
var bodyParser = require('body-parser');
var httpProxy = require('http-proxy');
var app = express();
/* create a proxy server */
var proxy = httpProxy.createProxyServer({});
/* proxy the hole /example path */
app.all('/example*', function(req, res) {
"use strict";
proxy.web(req, res, { target: 'http://example.com:8080' });
});
// ... other middlewars
app.use(bodyParser.json());
// .. other middlewars
/**
* add for a issue with body parser and proxy server to put
* the post request correct to the proxy
*/
app.use(require('connect-restreamer')());
module.exports = app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment