A live Vite app at a public link
1
A sandbox that serves port 3000
2
Get the code
In your pipeline, this step is a
git clone --branch of the pull request’s branch. To keep the example
self-contained, we write a small Vite app instead. (Vite is a popular development server for web apps.)3
Install and start the dev server
Install the app’s dependencies, then start the development server with
keep: true, so it keeps running across
sleep and wake. Vite only answers requests for hostnames it knows about, so we tell it the sandbox’s hostname
through an environment variable:4
Open the link
5
Push a change: the preview updates
When new commits arrive, run
git pull in the same sandbox. Vite notices the changed files, and any open page
reloads by itself. Here we change the file directly to show the effect:When the PR closes
When the pull request is merged or closed, find its sandbox by label and delete it:In GitHub Actions
In practice, a CI workflow runs these steps for you. This GitHub Actions workflow runs a small script each time a pull request is opened, updated or closed, with your Fibre key stored as a secret:.github/workflows/preview.yml
scripts/preview.mjs finds the pull request’s sandbox by its label and uses the calls from this page. When the pull
request is opened, it creates the sandbox and posts the link as a comment. When new commits arrive, it pulls them.
When the pull request is closed, it deletes the sandbox.
Good to know
A few things to keep in mind with previews:Related
Public URLs
How a sandbox’s public address works.
Snapshots
Start previews with dependencies already installed.