Intermediate 6: Multi-app reusability

A quick aside

You could very well add as many applications to your repository as you need to, building out a cluster of microservices dedicated to specific jobs in your final site.

Before we get into connecting them to each other, multi-app configuration also enables you to reuse code across applications.

If we imagine a simple PHP application with a web/index.php entry point, we can define a shared applications.yaml file to define the application.

The repository will look like this:

.
├── .platform
│   ├── applications.yaml
│   ├── services.yaml
│   └── routes.yaml
└── main-app
   └── web
       └── index.php

using an applications.yaml file that can contain an array of app configurations:

-   name: main
    type: php:8.1
    source:
        root: main-app
    web:
        locations:
            "/":
                root: "web"
                passthru: "/index.php"

We can add apps to this file (like a Next.js frontend in the previous step), but we can also reuse the codebase to build a completely separate application container in parallel.

-   name: main
    type: php:8.1
    source:
        root: main-app
    web:
        locations:
            "/":
                root: "web"
                passthru: "/index.php"

-   name: admin
    type: php:8.1
    source:
        root: main-app
    web:
        locations:
            "/":
                root: "web"
                passthru: "/admin.php"

Both apps (main and admin) use the main-app subdirectory as their codebase, but handle requests differently. Any other configuration included in this file would likewise differentiate the two (i.e. mounts and crons).



:arrow_forward: Next: Connecting applications

0

Comments

0 comments

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post