我想启动一个类似于以下内容的JavaScript Express代理服务器:
var express = require("express"),
http = require("http"),
port = (process.env.PORT || 8001),
server = module.exports = express(),
httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer();
// SERVER CONFIGURATION
// ====================
server.configure(function() {
server.use(function(req, res, next) {
if (req.url.indexOf('/bla') === 0) {
//console.log(res);
proxy.web(req, res, {target: 'http://bla.blabla.net'});
} else {
next();
}
});
server.use('/bla', 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);它过去工作时没有问题,但现在它失败了,尽管我没有修改代码。我收到以下错误消息:
util.js:634 ctor.prototype = Object.create(superCtor.prototype,{^ TypeError:无法读取未定义的属性“原型”) 在Object.exports.inherits (util.js:634:43) 在对象上。(c:\A_LONG_PATH\node_modules\http-proxy\lib\http-proxy\index.js:105:17) 在Module._compile (module.js:460:26) 在Object.Module._extensions..js (module.js:478:10) 在Module.load (module.js:355:32) 在Function.Module._load (module.js:310:12) 在Module.require (module.js:365:17) 应要求(module.js:384:17) 在对象上。(c:\A_LONG_PATH\node_modules\http-proxy\lib\http-proxy.js:4:17) 在Module._compile (module.js:460:26)过程中完成退出代码1
这可能与使用的lib有关,因为我更新了它们并重新安装了jquery。我读过关于浏览器同步的错误,但实际上我不使用它。无论如何,我安装了最新的版本,但这并没有改变任何东西。哪里出什么问题了?
编辑:
{
"name": "Website",
"title": "Website for Something",
"description": "",
"version": "0.28.0",
"homepage": "https://www.homepage.com",
"author": {
"name": "Devel Oper",
"email": "devel.oper@home.com"
},
"private": true,
"main": "./server/server",
"devDependencies": {
"amdclean": "1.x",
"chai": "~1.7.2",
"express": "3.x",
"grunt": "~0.4.1",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-connect": "~0.3.0",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-jasmine": "^0.8.2",
"grunt-contrib-jshint": "~0.3.0",
"grunt-contrib-requirejs": "~0.4.0",
"grunt-contrib-uglify": "~0.3.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-crontab": "^0.2.0",
"grunt-cucumber": "~0.2.1",
"grunt-express-server": "^0.5.1",
"grunt-karma": "~0.6.1",
"grunt-localhosts": "0.0.8",
"grunt-nightwatch": "^0.4.6",
"grunt-nightwatchjs": "^1.3.0",
"grunt-plato": "~0.2.1",
"grunt-template-jasmine-istanbul": "~0.2.4",
"grunt-template-jasmine-requirejs": "^0.2.3",
"grunt-text-replace": "^0.3.12",
"http-proxy": "1.0.0",
"karma-coverage": "~0.1.0",
"uglify-js": "~2.2.0",
"webdriverjs": "~0.7.9"
},
"dependencies": {
"body-parser": "^1.13.1",
"cookie-parser": "^1.3.5",
"cookie-session": "^1.1.0"
}
}发布于 2015-07-02 10:48:12
现在起作用了。解决方案是删除http-proxy库:
npm uninstall http-proxy然后我将这些行添加到我的package.json文件中:
"dependencies": {
"eventemitter3": "0.1.6",
"http-proxy": "~1.6"
}在npm install之后,一切都成功了。
https://stackoverflow.com/questions/31115494
复制相似问题