【问题标题】:Error starting express proxy server启动快速代理服务器时出错
【发布时间】:2015-07-02 18:48:12
【问题描述】:

我想启动一个如下所示的 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 结束

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

【问题讨论】:

  • 听起来像是在您的package.json 中使用* 的情况。在我的脑海中,app.configure 在最新版本的express 中已被弃用。你的package.json 是什么样的?
  • 我在上面添加了package.json 文件。不过我觉得应该没问题吧?
  • 我试图梳理出在它工作时发生了什么,然后当它不工作时。这是一天的时间吗?月?您是否检查了 http-proxy 更改日志以查看是否可能导致问题?
  • 一天之内。我不记得改变了什么。我只尝试更新一些库。也许这与它有关?

标签: javascript node.js express


【解决方案1】:

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

npm uninstall http-proxy

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

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

npm install 之后一切正常。

【讨论】:

    猜你喜欢
    • 2015-06-11
    • 1970-01-01
    • 2019-05-07
    • 2018-02-08
    • 2021-02-18
    • 2012-04-18
    • 2011-01-30
    • 1970-01-01
    相关资源
    最近更新 更多