webpro / dyson

Node server for dynamic, fake JSON.
837 stars 61 forks source link

Proxy does not work #77

Closed gonzalodenari closed 7 years ago

gonzalodenari commented 7 years ago

The proxy configuration does not work. It throws the following exception:

const app = dyson.bootstrap({ configDir: __dirname + '/services', port: 3000, proxy: true, proxyHost: "https://qax.anypoint.mulesoft.com", proxyPort: 443, proxyDelay: [200, 800] });

app.all('*', delay.middleware.bind(null, options.proxyDelay), proxy.middleware);

TypeError: Cannot read property 'bind' of undefined at registerServices (/Users/gonzo/Development/Garrett/mock-server/node_modules/dyson/lib/dyson.js:93:38) at Object.bootstrap (/Users/gonzo/Development/Garrett/mock-server/node_modules/dyson/lib/dyson.js:26:12) at Object. (/Users/gonzo/Development/Garrett/mock-server/server.js:3:19) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.runMain (module.js:605:10) at run (bootstrap_node.js:420:7)

webpro commented 7 years ago

Hi @gonzalodenari. Could you maybe try and see if it works with delay.bind instead of delay.middleware.bind on the line you posted, and submit a PR if all is fine? I currently don't have the time today to look into this.

gonzalodenari commented 7 years ago

Hi @webpro . Thank you for your answer. I've changed what you suggested and now the server starts without exception. It's also working when I call to a registered (GET/POST) service. The problem it's just when you call to a proxied service. It throws the following error:

TypeError: Cannot read property 'config' of undefined at delay (/Users/gonzo/Development/G/mock-server/node_modules/dyson/lib/delay.js:4:29) at Layer.handle [as handle_request] (/Users/gonzo/Development/G/mock-server/node_modules/express/lib/router/layer.js:95:5) at next (/Users/gonzo/Development/G/mock-server/node_modules/express/lib/router/route.js:131:13) at next (/Users/gonzo/Development/G/mock-server/node_modules/express/lib/router/route.js:125:14)

Thanks! Gonzalo

webpro commented 7 years ago

@gonzalodenari, I've just released v1.0.1. Could you please let me know how it runs for you?

gonzalodenari commented 7 years ago

@webpro Still does not work. It throws an error 500. The latest version that works correctly using the proxy configuration is 0.6.0

mock_server@1.0.0 server /Users/gonzo/Development/Garrett/mock-server NODE_ENV=test node server.js

500 INTERNAL SERVER ERROR: https://domain.com:443/apiplatform/repository/v2/organizations/47f40446-9f0b-43c0-a8ca-c7aea5136f32/applications/458/contracts 500 INTERNAL SERVER ERROR: https://domain.com:443/hello/world.

webpro commented 7 years ago

Can you give me an example of your setup so I can reproduce it?

gonzalodenari commented 7 years ago

server.js

var dyson = require('dyson');

dyson.bootstrap({
  configDir: __dirname + '/services',
  port: 3000,
  proxy: true,
  proxyHost: "https://qax.anypoint.mulesoft.com",
  proxyPort: 443,
  proxyDelay: [200, 800]
});

package.json

{
  "name": "mock_server",
  "version": "1.0.0",
  "author": "Gonzalo",
  "scripts": {
    "go": "open http://localhost:3000; npm run server",
    "test": "NODE_ENV=test mocha --timeout 10000",
    "server": "NODE_ENV=test node server.js"
  },
  "private": true,
  "dependencies": {
    "dyson": "0.6.0",
    "dyson-generators": "^0.1.1"
  },
  "devDependencies": {
    "chai": "^3.5.0",
    "chai-http": "^3.0.0",
    "mocha": "^3.2.0"
  }
}
webpro commented 7 years ago

Thanks for the info @gonzalodenari. I've just released 1.0.2 which hopefully resolves your issue.