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
  • 558,509
  • 191
  • 1,911
  • 1,506
HelpfulPanda
  • 267
  • 3
  • 14

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
  • 62,400
  • 12
  • 142
  • 126