Understanding the host element in resin.conf file with an example.

<host id='*'>
    <root-directory>./foo</root-directory>
    <web-app id="/">
        <document-directory>webapps/foo</document-directory>
    </web-app>
</host>

Let us dissect this one by one:

1. <host id=’*’>

This lets you specify the host name for which this web application is applicable. Putting a * means that it is applicable for all requests that you redirect to the port resin is listening on irrespective of their urls.

If the host id is as below

<host id=’foo.com’>

Then, it is applicable only to those requests for domain foo.com (Assuming you have configured the hosts.conf file to redirect requests for foo.com to the port your local resin is listening on).

Host id is the way to host multiple applications within a single resin instance. We will look at hosting multiple applications at the end.

2.  <root-directory>./foo</root-directory>

Present directory for this application is resin home folder .

For example, if the application is in webapps folder of home directory, then root directory would be just

<root-directory>.</root-directory>

If your webapps is in some other folder say foo, then your root directory would be

<root-directory>./foo</root-directory>

3. <document-directory>webapps/foo</document-directory>

This takes off where the root-directory left off. The path in the document-directory will be appended to the root-directory.

So, for the above snippet, absolute path of the document directory will be as below:

${resin.home}/webapps/foo

So, for an application with the directory structure as below

${resin.home}/bar/webapps/foo

root-directory will be

<root-directory>./bar</root-directory>

and  document-directory will be

<document-directory>webapps/foo </document-directory>

4. web-app id=”/”

This is the web application context name. For example, if the url is http://www.foo.com and your id is

web-app id=”bar”

Then, to view the index page, URL would be http://www.foo.com/bar/index.html

If the web app id is web-app id=”/”, then the above link will be http://www.foo.com/index.html

Now to the part where we want to host multiple web applications within one resin instance:

<host id='foo.com'>
    <root-directory>./foo</root-directory>
    <web-app id="/">
        <document-directory>webapps/foo</document-directory>
    </web-app>
</host>

<host id='bar.com'>
    <root-directory>.</root-directory>
    <web-app id="/">
        <document-directory>webapps/foo</document-directory>
    </web-app>
</host>

Directory structure of the above application will be:

1. ${resin.home}/foo/webapps/foo

2. ${resin.home}/webapps/bar

I do not know as to whether it is possible to host 2 web applications within the same webapps folder. I tried doing it and I got an InstanceAlreadyExistsException on my windows box. If someone knows the way to do it, please let me know.

Advertisements