Skip to content

Commit b4028ba

Browse files
costoloindexzero
authored andcommitted
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

Lines changed: 13 additions & 11 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy