Switching WebFolder

I’m trying to to serve different domains with completely different
formatted webpages.

Is it a good idea to use the following code in the on web connection
method to switch the root web folder for each request depending upon
the hostname of the referrer.

:

ARRAY TEXT($names;0)
ARRAY TEXT($values;0)

WEB GET HTTP HEADER($names;$values)

$pos:=Find in array($names;“referer”)

Case of

: ($values{$pos}=“youdopet.com”)

  $vt4dfolder:=Get 4D folder(Database folder)
  
  $vt4dfolder:=$vt4dfolder+"WebFolder"  //+<>sPathSeparator
  
  WEB SET ROOT FOLDER($vt4dfolder)

: ($values{$pos}=“youdohome.com”)

  $vt4dfolder:=Get 4D folder(Database folder)
  
  $vt4dfolder:=$vt4dfolder+"WebFolderHome"  //+<>sPathSeparator
  
  WEB SET ROOT FOLDER($vt4dfolder)

End case

I’m wondering if there are any serious performance issues in doing this ?

Regards
Paul

See https://doc.4d.com/4Dv17R5/4D/17-R5/WEB-SET-ROOT-FOLDER.301-4127521.en.htmldoc>:
Notes:
The Web server will need to be restarted in order for the new root folder to be taken into account.
I don’t know the time it takes, I’d test that first.

Arnaud, Thanks for pointing that out. I was reading the wrong part of
the Docs.

Its location can be set on the
Web/Configuration page of the Preferences or dynamically via the WEB
SET ROOT FOLDER command.

Bizarrely it seems to work I am changing the root in on web connection without restarting server and correct pages are served.

Would appreciate if someone from 4D could reply if this is valid or not. It would be very useful.

Thanks
Paul

: Paul DENNIS

Bizarrely it seems to work I am changing the root in on web
connection without restarting server and correct pages are served.
Would appreciate if someone from 4D could reply if this is valid or
not. It would be very useful.
Hi Paul,
in waiting they’re back from holiday ;-), you may send a https://taow.4d.comTAOW> case, something like “is doc wrong?” to get an answer.

Hi Paul,

I do remember what documentation says, I am bit surprised it works without restarting.

On the other hand, I believe “referer” is not the header key you should look for, the right one for implementing virtual domains is “Host:”.

I wouldn’t (and I never did in my projects) change Web root on the fly for each hit, even if it works. For static content I would set some variable to the path I need and then use 4DVAR in HTML base tag to server correct content for certain domain. For dynamic, based on Host: header value you know what to send.

I can pull the article I wrote for Dimension while late Walt Nelson distributed it if you need it, I think the PDF can be found on the Web even today.

Hello Milan,

Thanks for the reply. 4D is running behind nginx proxy so I was testing setting the referrer header there.

I agree not good idea to reset the root folder for every connection. It’s a bit more complicated as I’m using the lightning component and some of the paths are fixed so switching the whole web folder seemed like a good idea.

I’ve been trying to embed pages to resolve the problem but not got it to work yet.

I’ve probably got your old article in my documentation folder.

Cheers
Paul