Garrarufa
Garrarufa

Reputation: 1215

Error starting express proxy server

I want to start a JavaScript Express proxy server that looks like this:

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

It used to work without problems, but now it fails although I did not change the code. I get this error message:

util.js:634

ctor.prototype = Object.create(superCtor.prototype, { ^

TypeError: Cannot read property 'prototype' of undefined

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

at Object. (c:\A_LONG_PATH\node_modules\http-proxy\lib\http-proxy\index.js:105:17)

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

at Object.Module._extensions..js (module.js:478:10)

at Module.load (module.js:355:32)

at Function.Module._load (module.js:310:12)

at Module.require (module.js:365:17)

at require (module.js:384:17)

at Object. (c:\A_LONG_PATH\node_modules\http-proxy\lib\http-proxy.js:4:17)

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

Process finished with exit code 1

It might have something to do with the used libs, because I updated them and reinstalled jquery. I read about an error with browser-sync, but actually I don't use it. Anyway I installed the latest version, but this didn't change anything. What is wrong there?

EDIT:

{
  "name": "Website",
  "title": "Website for Something",
  "description": "",
  "version": "0.28.0",
  "homepage": "https://www.homepage.com",
  "author": {
    "name": "Devel Oper",
    "email": "[email protected]"
  },
  "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"
  }
}

Upvotes: 1

Views: 1278

Answers (1)

Garrarufa
Garrarufa

Reputation: 1215

Now it is working. The solution was to remove the http-proxy library:

npm uninstall http-proxy

Then I added these lines to my package.json file:

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

After npm install everything worked.

Upvotes: 1

Related Questions