0

I am struggling to setup a public website in Moqui, I am trying to have (dev-)www.example.net as the public marketing site and signup forms. Then the tennants on [tennant-name].example.net I have setup a basic component and then edited MoquiDevConf.xml, modified the webapp-list as shown below:

<webapp-list>
    <webapp name="webpublic" http-port="8080" https-enabled="false">
        <root-screen host="dev-www.example.net" location="component://webpublic/screen/webpublic.xml"/>
    </webapp>
    <webapp name="webroot" http-port="8080" https-enabled="false">
        <root-screen host="^((?!dev-www.example.net).)*$" location="component://webroot/screen/webroot.xml"/>
    </webapp>
</webapp-list>

I have restarted the app for the changes to take effect but all I get is an error 500 when I try and visit http://dev-www.example.net:8080/

org.moqui.BaseException: Could not find root screen for host [dev-www.example.net]

As far as I can tell Moqui is finding the component as I see this in the logs:

Added component [webpublic] at [file:/Volumes/MacHDD/Sources/atlas-moqui/runtime/component/webpublic] 

Non dev-www hosts still work and I get the customary login screen so I am not sure what I am missing as this is almost a direct copy of the existing webroot?

Thanks for any help! Sam

Sam Hamilton
  • 131
  • 2
  • 3
  • 10

2 Answers2

0

You probably using the same port number. Try different one (e.g. 8081) for the second one. All used ports should be different. Please see my comment as well.

senyor
  • 332
  • 4
  • 9
  • I had assumed that webapps were like vhosts in apache, that multiple can be run on the same port. I did try anyway but still the same error when I tried to switch the webroot to port 8081 and also it looks like winstone ignored the second port as in the logs there was only 8080 `INFO 03/02/15 15:58:46.900 [main]: HTTP Listener started: port=8080 INFO 03/02/15 15:58:46.903 [main]: AJP13 Listener started: port=8009` – Sam Hamilton Feb 03 '15 at 08:00
  • If you need multiple apps with the same port number one solution is to just deploy multiple wars on the same container. If you want completely separate containers with access on the same port (e.g 80), you can use apache web server as proxy or use iptables to redirect requests if you have enough access rights on the host. – senyor Feb 03 '15 at 08:07
  • So I also tried to remove the webroot and just leave my webpublic in the webapp-list - still the same error. – Sam Hamilton Feb 03 '15 at 08:10
  • Do you use http://www.moqui.org/framework/docs/RunDeploy.html ? What you use for deploy ? – senyor Feb 03 '15 at 08:15
  • Just gradle run as this on my laptop – Sam Hamilton Feb 03 '15 at 09:18
  • You use a single instance of Moqui with multiple virtual hosts following the pattern Sam is using. The moqui.org site is run this way along with 3 other web sites on a single instance of Moqui. – David E. Jones Feb 04 '15 at 02:50
0

My guess about why your particular configuration is not working is that the root-screen.@host attribute is always a regular expression and the URL you are using contains special characters including '-' and '.'. It should work if you escape these characters with a '\', i.e. use '.' and '-'.

That said, if you want to support virtual hosts with the same webapp root for multiple tenants you shouldn't need to declare the virtual hosts this way, this is only needed if you want a different webapp root screen (which may be what you eventually want to do).

UPDATE: With the configuration snippet above the issue is that there are multiple webapp-list.webapp elements, one with name=webroot which is the webapp used (as specified in the web.xml file in the moqui-name context-param) and the other with name=webpublic which is ignored because the configuration is found based on the name from the web.xml file.

The solution is to put both root-screen elements under the webapp element with name=webroot. Basically the way these are looked up is not arbitrary, it is explicit for the webapp name (the moqui-name context-param). If you have multiple webapps deployed they should have different moqui-name values to refer to different configurations. This would best be done in something other that Winstone, something like Tomcat. It would also stray from the documented ways of deploying Moqui, so a bit more work would need to be done. There isn't any really point in doing this, better to run everything in the same webapp with multiple root-screen elements and multiple root screens as needed.

David E. Jones
  • 1,721
  • 1
  • 9
  • 8
  • Still no joy, I tried `host="devwww\.example\.net"` and `host="devwww"` but both still error out with `org.moqui.BaseException: Could not find root screen for host`. I will have a good think about how to work around this, I might be tackling this problem the wrong way and perhaps overriding the existing webroot is a better way to go... – Sam Hamilton Feb 04 '15 at 05:10
  • The code that does this is super simple: for (Node rootScreenNode in getWebappNode()."root-screen") { if (host.matches((String) rootScreenNode."@host")) return this.rootScreen((String) rootScreenNode."@location") } throw new BaseException("Could not find root screen for host [${host}]") (sorry, formatting is awful in comments) The error message should tell you the hostname it's getting, which may be helpful, and beyond that it's just a matter of a regex that matches it. – David E. Jones Feb 12 '15 at 04:54
  • 1/3 Yep love the formatting in comments... so after a couple of hours of testing I believe that my regex is ok, I have the updated version [here](https://gist.github.com/samhamilton/6aee8d2a55c32c49feca). To test hostnames I edited my /etc/hosts and added `127.0.0.1 example1.example.com` and `127.0.0.1 devwww.example.com`. So now I have a test for tenant, a test for the new webapp for my www site and a test for when no tenant is provided e.g. http://localhost:8080. – Sam Hamilton Feb 16 '15 at 10:15
  • 2/3 The example1 and localhost both work fine and as per normal I get the 302 redirect to the login page but devwww still gives `org.moqui.BaseException: Could not find root screen for host [devwww.example.com]` which to me says that the regex for devwww is working but Moqui can't find the webpublic screen. – Sam Hamilton Feb 16 '15 at 10:15
  • 3/3 Right now all I can think of is 1. I should be passing some arguments to gradle to tell winstone I have multiple apps as per its docs `java -jar winstone.jar --hostsDir=` - I have just been using `gradle run` or 2. that my setup for the webpublic app is wrong and thats why moqui cant find the screen, so if you have 5 mins do you mind cloning my app and trying it yourself? I have put [source here](https://github.com/samhamilton/webpublic) and [settings here](https://gist.github.com/samhamilton/6aee8d2a55c32c49feca). Thanks! – Sam Hamilton Feb 16 '15 at 10:16