http-proxy一直挂掉
Http-proxy hangs up all the time
我有一个 JavaScript 代理服务器,经常在使用一段时间后挂掉。这是代理代码:
var express = require(["express"], function(){}),
http = require(["http"], function(){}),
port = (process.env.PORT || 8001),
server = module.exports = express(),
httpProxy = require(['http-proxy'], function(){});
var proxy = httpProxy.createProxyServer();
// SERVER CONFIGURATION
// ====================
server.configure(function() {
server.use(function(req, res, next) {
if (req.url.indexOf('/any/thing') === 0) {
//console.log(res);
proxy.web(req, res, {target: 'http://any.thing.com'});
} else {
next();
}
});
server.use('/anything', express["static"](__dirname + "/../public"));
server.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
server.use(express.bodyParser());
server.use(server.router);
});
// Start Node.js Server
http.createServer(server).listen(port);
我正在尝试用 Nightwatch.js 做一些测试。测试工作到一定程度,然后服务器崩溃。在一些测试中,这一点总是同时达到,在其他测试中,它取决于服务器何时崩溃以及它是否崩溃。
这是错误消息:
C:...\node_modules\http-proxy\lib\http-proxy\index.js:119
throw err;
^
错误:套接字挂起
at createHangUpError (_http_client.js:215:15)
at Socket.socketCloseListener (_http_client.js:247:23)
at Socket.emit (events.js:129:20)
at TCP.close (net.js:485:12)
正在停止 Express 服务器
这可能是什么原因?我无法在 google.
中弄清楚
向http-proxy并行发送请求时抛出错误。
安装不同版本的 http-proxy 可以避免该错误。
对我来说,错误发生在 http-proxy 版本 1.6.2 中。
我通过安装 1.0.0 版解决了这个问题:
npm uninstall http-proxy
然后
npm install http-proxy@1.0.0
我有一个 JavaScript 代理服务器,经常在使用一段时间后挂掉。这是代理代码:
var express = require(["express"], function(){}),
http = require(["http"], function(){}),
port = (process.env.PORT || 8001),
server = module.exports = express(),
httpProxy = require(['http-proxy'], function(){});
var proxy = httpProxy.createProxyServer();
// SERVER CONFIGURATION
// ====================
server.configure(function() {
server.use(function(req, res, next) {
if (req.url.indexOf('/any/thing') === 0) {
//console.log(res);
proxy.web(req, res, {target: 'http://any.thing.com'});
} else {
next();
}
});
server.use('/anything', express["static"](__dirname + "/../public"));
server.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
server.use(express.bodyParser());
server.use(server.router);
});
// Start Node.js Server
http.createServer(server).listen(port);
我正在尝试用 Nightwatch.js 做一些测试。测试工作到一定程度,然后服务器崩溃。在一些测试中,这一点总是同时达到,在其他测试中,它取决于服务器何时崩溃以及它是否崩溃。 这是错误消息:
C:...\node_modules\http-proxy\lib\http-proxy\index.js:119
throw err;
^
错误:套接字挂起
at createHangUpError (_http_client.js:215:15)
at Socket.socketCloseListener (_http_client.js:247:23)
at Socket.emit (events.js:129:20)
at TCP.close (net.js:485:12)
正在停止 Express 服务器
这可能是什么原因?我无法在 google.
中弄清楚向http-proxy并行发送请求时抛出错误。 安装不同版本的 http-proxy 可以避免该错误。 对我来说,错误发生在 http-proxy 版本 1.6.2 中。 我通过安装 1.0.0 版解决了这个问题:
npm uninstall http-proxy
然后
npm install http-proxy@1.0.0