Our frontend build produces a single artifact which contains the files to be served for our single page app (spa) as well as files required for server side rendering (ssr). We already have set up habitat a while ago to server the spa files via Nginx.
Now I would like to add a second habitat package, which contains the server needed to serve the server side rendered requests. This ssr package requires the files contained in the spa package which is served by Nginx. So, I tried to set up a producer consumer contract, where the producer (spa) exports the path to its compiled files. The ssr package would then pick up the path to the spa package and start its own server, which handles server side rendering.
I tried to set up the producer to export the path within the plan
pkg_exports=(
[distPath]=distPath
)
and added a default value to the toml file:
distPath = "${pkg_prefix}/dist"
Unfortunately I only see a blank value within the rendered configuration file of the ssr package (/hab/svc/ssr/config/server.js). The handlebars code used in the config file as well as the run hook looks like this:
{{bind.nginx.first.distPath}}
Two questions here:
- Is there a better way to export or set the path than from the toml file (which does not seem to work - at least I seem to be doing something the wrong way)?
- Is there a way to query exports and their values via hab command line. I noticed there is
hab pkg binds
, however this only seems to list the required bindings, not the exported values
Side note: the server side rendering requires the spa files to work, that’s why they are bundled together. A page loaded via ssr will load all the additional files required for the spa in the background. So, ssr merely is a way to decrease loading times. Alternatively it would work if one habitat package would launch Nginx as well the ssr server, however I figured that would not be a very good thing to do as we are not supposed to have two run hooks afaik…