1

Id like to dynamically create subdomains for different proxies, like so:

var app = require('express')();
var proxy = require('express-http-proxy');
var vhost = require('vhost');

app.get('/make', function (req, res) {
    app.use(vhost('sub1.mysite.com', proxy("www.example.com")));
});
app.listen(8080);

What's the best way to accomplish this? The problem seems to be calling app.use() after the server is created.

Orane
  • 2,223
  • 1
  • 20
  • 33

1 Answers1

1

app.get should send back something to the client else the client will retry and then timeout.

var app = require('express')();
var proxy = require('express-http-proxy');
var vhost = require('vhost');

app.get('/make', function (req, res) {
    app.use(vhost('sub1.mysite.com', proxy("www.example.com")));

    res.send('Created'); // <----- Send reply to client
});
app.listen(8080);
John Siu
  • 5,056
  • 2
  • 26
  • 47