This Play 2.3 template tries to be a skeleton for a simple multidomain project (www.myweb.com and admin.myweb.com). It shows you how to use subprojects for that and how to share common code. It is also ready to use with Webjars, CoffeeScript, LESS, RequireJS, assets Gzip and assets fingerprinting. Please, check the readme file for more details.
The bundle includes a small bootstrap script that
can start Activator. To start Typesafe Activator's UI:
In your File Explorer, navigate into the directory that the template was extracted to, right-click on the file named "activator.bat", then select "Open", and if prompted with a warning, click to continue:
We've included the text of this template's tutorial below,
but it may work better if you view it inside Activator
on your computer. Activator tutorials are often designed
to be interactive.
Preview the tutorial
Let's suppose you want to develop a whole project which has two different services: the typical public webpage and the private admin one. You also want a specific subdomain for the admin webpage, so we will have:
admin.myweb.com: private administration webpage.
www.myweb.com or myweb.com: public webpage.
And let's also suppose you prefer to have these services isolated in your production server. So you would be able to manage them separately (with different PIDs, different ports, different resources…).
Then, we have the following objectives:
Development should be simple. activator run should be enough to run all services at the same time.
Common code, dependencies and modules should be easily shared.
We should be able to compile, test and run each service separately in development and production.
We should distribute each service separately.
It should be a template ready to use with the following features:
How to share every common code to avoid duplications (models, controllers, views, CoffeeScript, LESS, ...).
How to use it for development, test and production.
This template has 3 subprojects:
web: will contain all the specific code for the public webpage service.
admin: will contain all the specific code for the private administration webpage service.
common: will contain all the common code shared between the other subprojects.
Obviously, this is a template, so you can easily change its names or add more modules. Once you understand how it works you will find it easy to modify.
You can see the basic structure of the whole project
Let's try to explain briefly how it is configured. For running the whole project we have the following configuration files:
build.sbt: configures root project and declares every subproject.
conf/application.conf(used when whole project is running): the default one. In the next section it is explained in detail.
conf/routes(used when whole project is running): routes file for the whole project. It simply imports the routes file of every subproject.
app/Global.scala(used when whole project is running): the GlobalSettings object for the whole project. It determines the subdomain for each request (admin or web) and delegates its behaviour to the corresponding subproject.
modules/[subproject]/conf/application.conf(used when only this subproject is running): the default one, it declares the routes file and GlobalSettings object for the subproject while running, testing or distributing only this subproject.
It has been added a key called this.file in many of the configuration files and it is shown in the index web page when you run it. Please, play with it to see how it is overridden by each configuration file depending the project and mode (dev or prod) you are running.
Tip: as files shared.dev.conf and shared.prod.conf for every subproject are the same as the general ones, you can use aliases or symbolic links for them in order to avoid to maintain all of them.
If you have doubts about the specific route of any webjar resource, remember it is directly downloaded within the relative folder target/web/web-modules/main/webjars/lib. So you can easily check the file structure that has been downloaded by the webjar.
For more information, go to the documentation page about CoffeeScript.
The corresponding plugin needs to be active in file project/plugins.sbt. And the next configuration has been added to every subproject to be able to work with partial LESS source files (in project/Common.scala):
includeFilter in (Assets, LessKeys.less) := "*.less"
excludeFilter in (Assets, LessKeys.less) := "_*.less"
With that, every LESS file not prepended by an underscore (_) will be compiled, and they could import the code from the LESS files prepended by an underscore.
For more information, go to the documentation page about Assets, the tutorial play-2.3-highlights in Activator UI, or the website of RequireJS.
You can put the common public files in the subproject common, within the folder modules/common/public/. The common Assets are packaged as Webjars for the other subprojects that depend on it, so you must access to them through their correspoding lib folder:
And the specific code for each subproject will be added within its corresponding folder modules/[subproject]/public/. Take care with possible namespace problems while running the whole project.
First of all, to get access to admin subdomain you will need modify your /etc/hosts files (or the equivalent in your S.O.) to map the next URLs to localhost or (127.0.0.1). For example, add the following lines: