|
|
|
Virtualized directories
Project Zero provides seamless integration of script directories across an application and its dependencies, while maintaining each as separate entities. For example, while processing a request for GET /index.html, Project Zero searches for a file public/index.html in the application directory, then within each resolved dependency. The first occurrence of the file is served. Project Zero applications run as if the contents of the public directories, from application to dependencies, are merged with a first-one-wins precedence.
This notion of a virtualized directory describes all the script directories, including public, app/errors, app/resources, app/scripts, and app/views.
Working example
In this example, MyApplication is a Project Zero application that depends on the extension modules acme.A and acme.B, as shown in this excerpt from the following config/ivy.xml file within MyApplication:
<dependencies>
<dependency org="acme" name="acme.A" rev="1.0.0+"/>
<dependency org="acme" name="acme.B" rev="1.0.0+"/>
<dependency org="zero" name="zero.core" rev="1.0.0+"/>
</dependencies>
In this example, acme.A depends on extension modules acme.A1 and acme.A2, as shown in the following config/ivy.xml file within acme.A:
<dependencies>
<dependency org="acme" name="acme.A1" rev="1.0.0+"/>
<dependency org="acme" name="acme.A2" rev="1.0.0+"/>
</dependencies>
Also, acme.B depends on acme.B1 and acme.B2 as shown in the following example:
<dependencies>
<dependency org="acme" name="acme.B1" rev="1.0.0+"/>
<dependency org="acme" name="acme.B2" rev="1.0.0+"/>
</dependencies>
These dependencies can be summarized in the following way:
MyApplication -> acme.A -> acme.A1
-> acme.A2
-> acme.B -> acme.B1
-> acme.B2
Search order
Searches through virtual directories are ordered by application first, and then breadth-first through the dependencies (in the order they appear in ivy.xml files). For this example, the search order is:
-
MyApplication
-
acme.A
-
acme.B
-
acme.A1
-
acme.A2
-
acme.B1
-
acme.B2
Example file layout
The example file layout uses the notation ${MyApplication} to represent the root directory of MyApplication:
${/config/dependencies/MyApplication}
+ /public
+ index.html
${/config/dependencies/acme.B}
+ /public
+ index.gt
+ HelloWorld.groovy
${/config/dependencies/acme.A1}
+ /public
+ HelloWorld.groovy
Results
Based on the search order, requests are served as the following table shows:
| Request | Associated file |
GET /HelloWorld.groovy | ${/config/dependencies/acme.B}/public/HelloWorld.groovy |
GET /index.html | ${/config/dependencies/MyApplication}/public/index.html |
Default files
A default file is the file processed on a request for a directory, such as GET /. With default configuration, the default files are a list that is searched in the following order: index.groovy, index.gt, then index.html.
Searches for default files are performed within each directory, rather than across directories. For the above example, the search for a default file for GET / would be as follows:
-
${/config/dependencies/MyApplication}/public/index.groovy
-
${/config/dependencies/MyApplication}/public/index.gt
-
${/config/dependencies/MyApplication}/public/index.html
-
${/config/dependencies/acme.A}/public/index.groovy
-
${/config/dependencies/acme.A}/public/index.gt
-
${/config/dependencies/acme.A}/public/index.html
-
...
Advanced The search order for default files is specified by a List stored in the global context at /config/fileserver/searchOrder. Elements of that list are suffices, that are appended to the base file name "index".
|