启动快速代理服务器时出错

时间:2015-06-29 12:16:50

标签: javascript node.js express

我想启动一个如下所示的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:无法读取属性'原型'未定义的

     
    

at Object.exports.inherits(util.js:634:43)

         

at Object。 (C:\ A_LONG_PATH \ node_modules \ HTTP代理\ lib中\ HTTP代理\ index.js:105:17)

         

在Module._compile(module.js:460:26)

         

at 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)

         

at require(module.js:384:17)

         

at Object。 (C:\ A_LONG_PATH \ node_modules \ HTTP代理\ lib中\ HTTP-的proxy.js:4:17)

         

在Module._compile(module.js:460:26)

  
     

使用退出代码1完成处理

它可能与使用过的libs有关,因为我更新了它们并重新安装了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"
  }
}

1 个答案:

答案 0 :(得分:1)

现在它正在运作。解决方案是删除http-proxy库:

npm uninstall http-proxy

然后我将这些行添加到我的package.json文件中:

"dependencies": {
    "eventemitter3": "0.1.6",
    "http-proxy": "~1.6"
}

npm install一切正常后。