redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Is it possible to set up virtual hosts in Redstone? #117

Closed sonoranDesert closed 9 years ago

sonoranDesert commented 9 years ago

Like how the http_server package does:

http://stackoverflow.com/a/21087254/607036

azenla commented 9 years ago

Not quite yet, but I will look into this ASAP.

cgarciae commented 9 years ago

app.start returns an HttpServer so I am guessing this will work

void main() async {
  var server = await app.start (port: 8080);
  final virtualServer = new VirtualHost(server);
  final domain1Stream = virtualServer.addHost('domain1.com');
  new VirtualDirectory('/var/www/domain1').serve(domain1Stream);
}
sonoranDesert commented 9 years ago

Thanks for the quick responses.

@cgarciae In my case I get a "Bad state: Stream was already listened to" error when trying to do that, but I'll dig into that idea some more.

cgarciae commented 9 years ago

@sonoranDesert You can try this approach, should work

  app.setupConsoleLog();
  app.setUp();

  HttpServer server = await HttpServer.bind('localhost', 7070);
  final virtualServer = new VirtualHost(server);
  final domain1Stream = virtualServer.addHost('domain1.com');

  domain1Stream.listen(app.handleRequest);
cgarciae commented 9 years ago

I'll close this since @sonoranDesert failed to verify the answer.