Previews are in early access. The Preview row shows only for an organization that has previews turned on. To turn them on, email hello@outerlayer.ai.
Open a preview
- Open a work item that has an open pull request.
- Select Start preview in the Preview row of the item’s sidebar.
- Wait while the page shows Preview starting. It shows the time since the start.
- When the page shows Preview ready, select Open preview. A new tab loads the app.
What the item page shows
The action is off, with a reason beside it, in these cases:
- The repository declares no preview. The reason links to this page.
- The pull request changes no file that the preview shows. See
pathsbelow. - The pull request comes from a fork. A fork gets no preview.
- GitHub does not answer. Try again in a few minutes. A running preview still opens.
- You do not hold Add work. A member with the Read role can open a running preview, but cannot start or stop one. See Roles and permissions.
Declare a preview
Add apreview block to .outerlayer-proofs.yaml at the root of the repository. The file also needs a runners list, which says how to run your tests. Use runners: [] for none.
The preview runs the
setup commands of the file, then the seed commands, then it waits for the open port. Make the app listen on 0.0.0.0, not on localhost.
The commands run in a container of the build image. A build of the same item uses that image. The commands find the same tools as a build, such as yarn and mise. They reach the sandbox’s Docker as a build’s commands do, so docker compose up -d --wait starts a database. A command that starts a server in the background keeps it running after the command ends. If the repository has a .outerlayer/setup-root.sh script, the preview runs it as a build does, and the container starts from the image it makes.
Check the file with outerlayer work proofs --check. See The proofs file and The preview block. A runner needs CLI 0.46 or newer.
Give the app its preview address
Each port has its own address in the formhttps://<preview id>-<port>.<preview domain>. A browser keeps the cookies of one port apart from another.
Every setup and seed command gets the address of each declared port in the variable OUTERLAYER_PREVIEW_URL_<port>. For port 4000 the variable is OUTERLAYER_PREVIEW_URL_4000.
An app that is split across two ports needs this. A web app on port 3000 that calls an API on port 4000 reads OUTERLAYER_PREVIEW_URL_4000 for the API address.
A call to another port’s address is a call to another origin. Send the call with credentials, so that the browser sends the preview cookie. Use credentials: 'include' for fetch and withCredentials: true for axios. A call without credentials gets a not-found answer.
The app needs no CORS setup for these calls. The preview answers the browser’s preflight request and sets the CORS headers itself. It does this only for the other ports of the same preview.
Limits
- The sign-in callback. A sign-in provider that checks the redirect address rejects the preview host. OuterLayer cannot fix this. Use a sign-in method that has no redirect, such as email and password, for the preview.
- Idle time. A preview stops after 30 minutes with no request.
- Total time. A preview stops 4 hours after it started, even when requests still arrive.
- One preview. An item has at most one running preview.
- Runner restarts. A ready preview keeps running when its runner restarts, for example to update itself. A preview that is still starting fails. Start it again.
- Managed sandboxes. The organization needs managed sandboxes. A preview does not run on a self-hosted runner without them.
- No secrets. The sandbox holds no build variable and no token that can write to the repository. The app cannot push to the repository.
- Data. A preview keeps no data after it stops. Each start runs
setupandseedagain. - Network. A preview reaches GitHub and the hosts a managed build reaches: the default hosts and the factory’s Allowed hosts. A
setupcommand that downloads from another host fails. Add that host under Settings → Build settings → Allowed hosts. See Managed build settings.