I am trying to create a proxy from Node.js to Heroku using http-proxy. Everything works well locally, but I am having problems with Heroku.
var http = require('http');
var httpProxy = require('http-proxy');
settings = {
"localhost": process.env.LOCALHOST,
"devices": process.env.DEVICES_URI
}
var options = { router: { } }
options.router[settings.localhost + '/devices'] = settings.devices + '/devices';
var port = process.env.PORT || 8000;
var server = httpProxy.createServer(options).listen(port);
As you can see, in the example I set the routing object. I say the following: when the request matches "/ devices", then forward the request to the device service. (identified by DEVICES_URI environment var)
In development, I installed
- LOCALHOST = 'localhost'
- DEVICES_URI = 'http: // localhost: 3000'
This means that all requests sent to localhost: 8000 / devices are proxied to localhost: 3000 / devices that I want. Everything works perfectly.
The problem is in production. This gives me a timeout error repeating several times for each request.
2012-08-23T20:18:20+00:00 heroku[router]: Error H12 (Request timeout) -> GET lelylan-api.herokuapp.com/devices dyno=web.1 queue= wait= service=30000ms status=503 bytes=0
vars .
- LOCALHOST = 'lelylan-api.herokuapp.com'
- DEVICES_URI = 'lelylan-devices.herokuapp.com/'
, , ,
.
, , -, .
:
- LOCALHOST = 'localhost'
- DEVICES_URI = 'lelylan-devices.herokuapp.com/'
http://lelylan-devices.herokuapp.com/devices, .
localhost: 8000/devices ( http://lelylan-devices.herokuapp.com/devices), , . , - .
.
vars Heroku.
NODE_ENV => production
LOCALHOST => lelylan-api.herokuapp.com
DEVICES_URI => lelylan-devices.herokuapp.com
TYPES_URI => lelylan-types.herokuapp.com
LOCATIONS_URI => lelylan-locations.herokuapp.com