On Tue, 27 Sep 2016 01:24:03 GMT, Uiy Uiy wrote:

On Sun, 25 Sep 2016 11:39:34 GMT, Sönke Ludwig wrote:

(...)
The two virtual hosts are logically completely distinct, except that both serve the "public" folder of the root directory.

But how do we keep the views isolated and such. It doesn't seem to keep the two sites distinct. You are simply adding two different directories to serve from(BTW, what is the precedence order?).

Precedence is in the order as registered in the router (i.e. the root public folder would be searched first in the example).

If I have 10 sites, say, and ones view directory, then things can get very hairy quickly. I have to keep everything named properly.

Since "views" are a compile-time feature, and due to the way string imports work, they cannot be truly distinct, unless you build each site as a separate executable. In general, I'd always recommend to do that anyway to increase robustness against crashes and hangs.

You just need to have a single front-end web server in that case, which has all the virtual hosts registered and forwards the requests to the appropriate process.

It would be nice to have a

settings.rootDir which sets the root dir for the site.

This can't work unfortunately, because Diet templates are already processed at compile time.

That is, unless setting hostName sets the rootDir?

No, those are distinct.

Or is there something I'm missing?

My goal is to really have n distinct sites with each it's own distinct root directory. The common folder is not as important... I can just copy files between them if necessary. I was just trying to avoid duplicating a bunch of files between the sites but then I forgot about views and dt files.

Then I'd really recommend going with a reverse proxy and separate processes. A rough sketch would be:

proxy (of course you could also instead use something like Nginx here, which is not a bad idea in general):

shared static this()
{
  auto hosts = [
    tuple("foo.example.org", 8081),
    tuple("bar.example.org", 8082)
  ];

  foreach (host; hosts) {
    auto settings = new HTTPServerSettings;
    settings.host = host[0];

    auto psettings = new HTTPReverseProxySettings;
    psettings.destinationHost = "127.0.0.1";
    psettings.destinationPort = host[1];

    listenHTTPReverseProxy(settings, psettings);
  }
}

first site:

shared static this()
{
  auto router = new URLRouter;
  // ...

  auto settings = new HTTPServerSettings;
  settings.bindAddresses = ["127.0.0.1"];
  settings.port = 8081;

  listenHTTP(settings, router);
}

Each of these would be in a separate DUB package. You could still have all sites depend on a separate package that contains common views and public resources. The "copyFiles" directive of the package recipe can be used to copy the runtime resources for each site automatically (example).