我使用 http-proxy 和 express 中间件制作了一个代理。但是,它不会转发 PUT 请求——这对于我要代理的应用程序来说是必不可少的。我究竟做错了什么?
(代理服务器的目的是为代理背后的应用程序提供身份验证。如果有其他方法可以做到这一点,我将不胜感激。)
var proxy = new httpProxy.RoutingProxy();
var app = express();
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.engine('ejs', require('ejs-locals'));
app.use(express.logger());
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({secret: 'rupert'}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(function(req, res) {
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 8080
});
});
app.use(express.static(__dirname + '/../../public'));
});
app.get('/login', function(req, res){
res.render('login', { user: req.user, message: req.flash('error') });
});
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }),
function(req, res) {
res.redirect('/');
});
app.get('/logout', function(req, res){
req.logout();
res.redirect('/')
});
app.all('/*', function(req, res, next) {
return next();
});
app.listen(3000,'localhost');