1

In Dart language, the http_server package allows to implement virtual hosts.

import 'package:http_server/http_server.dart';
import 'dart:io';

void main() {

   HttpServer.bind('localhost', 8080).then((server) {
        var virtualServer = new VirtualHost(server);
          virtualServer.addHost('domain1.com').listen(
             (HttpRequest request) {
                //  what should I do now?
             }
   });

}
  1. How can I serve a web site in a subdirectory below /web/ using the http_server package?
  2. Is it best to place the web sites below the usual "web" directory?
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
HelpfulPanda
  • 377
  • 3
  • 14
  • for 2) you may take a look at [How to organize mixed HTTP server + web client Dart project files?][1] [1]: http://stackoverflow.com/questions/20884103 – Günter Zöchbauer Jan 10 '14 at 18:01

1 Answers1

1

You can do :

import 'dart:io';

import 'package:http_server/http_server.dart';

void main() {
  HttpServer.bind('localhost', 8080).then((server) {
    final virtualServer = new VirtualHost(server);
    final domain1Stream = virtualServer.addHost('domain1.com');
    new VirtualDirectory('/var/www/domain1').serve(domain1Stream);
  });
}
Alexandre Ardhuin
  • 71,959
  • 15
  • 151
  • 132