Getting related application route during buildtime

I’m trying to build a VueJS application that needs some environment variables compiled into the code. Mainly its own Application URL and the URL to an accompanying PHP backend.

I could try to parse the PLATFORM_ROUTES env, but it seems rather cumbersome, as I don’t really have a key to identify the correct route.

The setup uses a multi-app configuration via submodules

Looks like PLATFORM_ROUTES and _RELATIONS are not available in the build process, so it seems there are no ways to get the URL of another application?

Hi there! Yes, during the build phase PLATFORM_ROUTES is not available. This helps keep builds isolated and environment-independent.

In my experience, there are two ways around the limitation.

  1. Delay the build. As you can see from our Next.js + Drupal template, you can delay the build to the post_deploy hook when the backend application and PLATFORM_ROUTES is available to define the backend location for the current environment. Note it will be necessary to define a mount for the Vue.js build directory in this case, since post-build the file system is read-only.
  2. Use subdirectory multi-app routes. If during build the Vue.js is not actually pulling content from the backend application, but merely needs a URL to successfully build, you can instead define each application in routes.yaml to serve from a subdirectory rather than a subdomain. For example, the Vue.js from {default} and the PHP app from {default}/api. That way, if Vue.js allows, your backend config can simply be /api rather than the full backend URL.

That said, I’ve often found that a combination of both of these is necessary to do multi-app correctly on Platform.sh. Take a look at the template I’ve linked above and let us know if you have more questions.