Fix modify response middleware example (#1139)

* 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
This commit is contained in:
Ben Costolo 2019-08-22 03:38:28 -04:00 committed by Charlie Robbins
parent 77a98159d2
commit b4028ba78b

View File

@ -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