Skip to content

Commit b4028ba

Browse files
costoloindexzero
authored andcommittedAug 22, 2019
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
1 parent 77a9815 commit b4028ba

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed
 

‎examples/middleware/modifyResponse-middleware.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,26 @@ var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
3030
connect = require('connect'),
31+
app = connect(),
3132
httpProxy = require('../../lib/http-proxy');
3233

3334
//
3435
// Basic Connect App
3536
//
36-
connect.createServer(
37-
function (req, res, next) {
38-
var _write = res.write;
37+
app.use(function (req, res, next) {
38+
var _write = res.write;
3939

40-
res.write = function (data) {
41-
_write.call(res, data.toString().replace("Ruby", "nodejitsu"));
42-
}
43-
next();
44-
},
45-
function (req, res) {
46-
proxy.web(req, res);
40+
res.write = function (data) {
41+
_write.call(res, data.toString().replace("Ruby", "nodejitsu"));
4742
}
48-
).listen(8013);
43+
next();
44+
});
45+
46+
app.use(function (req, res) {
47+
proxy.web(req, res)
48+
});
49+
50+
http.createServer(app).listen(8013);
4951

5052
//
5153
// Basic Http Proxy Server

0 commit comments

Comments
 (0)
Please sign in to comment.