Skip to content

Commit

Permalink
Fix modify response middleware example (#1139)
Browse files Browse the repository at this point in the history
* declare app variable to house middleware

* remove deprecated connect.createServer() function call

* specify middleware with app.use() and pass app middleware to an http
server
  • Loading branch information
costolo authored and indexzero committed Aug 22, 2019
1 parent 77a9815 commit b4028ba
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions examples/middleware/modifyResponse-middleware.js
Expand Up @@ -28,24 +28,26 @@ var util = require('util'),
colors = require('colors'),
http = require('http'),
connect = require('connect'),
app = connect(),
httpProxy = require('../../lib/http-proxy');

//
// Basic Connect App
//
connect.createServer(
function (req, res, next) {
var _write = res.write;
app.use(function (req, res, next) {
var _write = res.write;

res.write = function (data) {
_write.call(res, data.toString().replace("Ruby", "nodejitsu"));
}
next();
},
function (req, res) {
proxy.web(req, res);
res.write = function (data) {
_write.call(res, data.toString().replace("Ruby", "nodejitsu"));
}
).listen(8013);
next();
});

app.use(function (req, res) {
proxy.web(req, res)
});

http.createServer(app).listen(8013);

//
// Basic Http Proxy Server
Expand Down

0 comments on commit b4028ba

Please sign in to comment.