A lot of projects have one container and therefore only need one preview and everything is great.
But some projects have a multi container or cluster setup. For example one container for the backend serving the API and one container for the frontend app.
So the preview for the frontend app needs to connect to the preview of the backend API.
For these cases you can connect your WunderPreview previews (which are basically running Docker Containers) to each other. So it is possible for the frontend app preview of your project to connect to the backend API preview. Everything in WunderPreview.
Connecting one preview to another is easy: just use environment variables.
In the settings screen of your repository you can define environment variables for the previews of this repository.
WunderPreview has something called "Magic env vars".
For example: you go to the settings of your frontend repository and define a env variable
BACKEND_URL and in the value of the env var you give a value of
WunderPreview will resolve this magic value and automatically set it to the URL of the preview of the
master branch of the repository with the ID
This way you will have the URL to your backend available in your frontend preview.
The URL will always lead to the preview of the latest commit in the master branch. Even if you merge code in your master branch or push new commits to the master branch. The URL stays the same and your frontend is always connecting to the newest version of your backend.
If you want to know more about magic env vars and how to set them, please have a look at our documentation article: How to use env vars during build-time and run-time
With this simple but powerful feature you can create a complete preview cluster consisting of multiple previews all connected to each other.
And it is absolutely secure too. Only your previews are allowed to connect to your other previews. If a preview from another WunderPreview customer tries to connect to your previews it is prevented by the network configuration of our clouds VPC setup.
Your previews are in a safe space. Let them connect!
Do you have any questions or remarks? Just send us an email to firstname.lastname@example.org. We are happy to hear from you!