Skip to content
LogoLogo

App environment variables

These environment variables configure the server of an app, and the Picked CLI when it deploys an app.

App server variables

readAppEnvironment from @picked/app-kit/server reads these variables. See readAppEnvironment for its parameters and its return value.

import { readAppEnvironment } from '@picked/app-kit/server'
 
const port = process.env.APP_PORT ?? '4103'
const { privateKey, pickedKeys, publicUrl, dashboardOrigins } = readAppEnvironment(
  process.env,
  port,
)
VariableRequiredValue
PICKED_APP_PRIVATE_KEYYesThe Ed25519 private key of the app, as the base64 of its PKCS#8 DER. A PKCS#8 PEM also works.
PICKED_API_URLSee Values when a variable is not setThe origin of the Picked API that the app accepts requests from, for example https://api.picked.app.
APP_PUBLIC_URLNoThe origin of the server of the app. The app uses it in its own URLs, for example the URL of an OAuth callback.
PICKED_DASHBOARD_ORIGINSNoThe dashboard origins that can show the pages of the app in an iframe. A , separates each origin.
API_PORTNoThe port of a Picked API on your computer.
DASHBOARD_PORTNoThe port of a Picked dashboard on your computer.
PICKED_APP_IDNoThe app ID in this Picked environment, for example app_k3v9x2m1q8zt. picked app deploy prints it.

picked app keys generate prints a value for PICKED_APP_PRIVATE_KEY. See CLI.

readAppEnvironment returns PICKED_APP_ID as appId. The first origin that dashboardOrigins() gives is the dashboard that the app links to. When you set PICKED_DASHBOARD_ORIGINS, write the main dashboard first, before an origin with *. See the guide about links to an installation.

The app reads the public keys of Picked from <PICKED_API_URL>/.well-known/picked-app-keys.json. It verifies each request from Picked with these keys. See Public keys of Picked.

Values when a variable is not set

readAppEnvironment uses the first source in each row that has a value. PICKED_API_URL is required only when no other source gives a value.

VariableSources, in order
PICKED_APP_PRIVATE_KEY1. The variable. 2. None: readAppEnvironment throws an error.
PICKED_API_URL1. The variable. 2. On Vercel, the related project picked-api. 3. When API_PORT is set, http://localhost:$API_PORT. 4. None: readAppEnvironment throws an error.
APP_PUBLIC_URL1. The variable. 2. On Vercel with VERCEL_ENV=production, https://$VERCEL_PROJECT_PRODUCTION_URL. 3. On Vercel in a different environment, https://$VERCEL_BRANCH_URL. 4. http://localhost:<port>.
PICKED_DASHBOARD_ORIGINS1. The variable. 2. When DASHBOARD_PORT is set, http://localhost:$DASHBOARD_PORT and http://127.0.0.1:$DASHBOARD_PORT. 3. The app config of Picked.

<port> is the second argument of readAppEnvironment.

ErrorCause
Set PICKED_APP_PRIVATE_KEY to the app's private key, from `picked app keys generate`PICKED_APP_PRIVATE_KEY is not set, or is empty.
Set PICKED_API_URL to the Picked API the app trustsNo source gives a value for PICKED_API_URL.

readAppEnvironment removes each / at the end of PICKED_API_URL and APP_PUBLIC_URL.

On Vercel, VERCEL_RELATED_PROJECTS lists the related projects of the deployment. readAppEnvironment reads the origin of the related project picked-api from it:

VERCEL_ENVOrigin of the related project
previewThe preview deployment of the related project for the same custom environment, or for the same branch.
productionThe production alias of the related project, or its production URL.

The dashboard origins come from the app config of Picked of that API. The app config gives the dashboard host of each client.

A deployment without the related project picked-api gets no value from it. Set PICKED_API_URL on that deployment.

Values for each Picked environment

The server of an app accepts requests from one Picked environment. Each Picked environment gives the app a different app ID.

Picked environmentPICKED_API_URLPICKED_DASHBOARD_ORIGINS
Productionhttps://api.picked.apphttps://dashboard.picked.app,https://*.picked.app,https://dashboard.convincely.com
Test (picked-dev.app)https://api.picked-dev.apphttps://dashboard.picked-dev.app,https://*.picked-dev.app

https://*.picked.app includes the dashboard host of each client, for example https://acme.picked.app. To allow fewer hosts, write each host in the list.

The production list has no picked-dev.app origin.

You do not have to set PICKED_DASHBOARD_ORIGINS. Without it, the app uses the app config of Picked. Set it to allow fewer origins, or an origin that the app config does not have.

App config of Picked

The Picked API publishes the dashboard origins of its environment at <PICKED_API_URL>/.well-known/picked-app-config.json. See App config of Picked.

dashboardOrigins() gives frameAncestors when the environment gives a dashboard origin. When the environment gives no dashboard origin, dashboardOrigins() reads the app config:

  • It reads the app config on the first call.
  • After a read that succeeds, it reads the app config again after 5 minutes or more.
  • Before a read succeeds, it reads the app config again on each call.
  • It stops a read after 5 seconds.
  • When a read fails, it gives the origins of the last read that succeeded.
  • Before the first read succeeds, it gives no origin.

The app config comes from PICKED_API_URL. The public keys of Picked come from the same API, so the app config adds no new source.

frame-ancestors

readAppEnvironment returns the dashboard origins that the environment gives as frameAncestors. dashboardOrigins() also gives the origins of the app config. Give await dashboardOrigins() to page from @picked/app-kit/server. page sends the origins in the Content-Security-Policy header of a page:

Content-Security-Policy: frame-ancestors https://dashboard.picked.app https://*.picked.app https://dashboard.convincely.com

When the list of origins that you give page is empty, the header is frame-ancestors 'none'. Then no site can show the page in an iframe, and the dashboard also cannot show it. See page.

CLI variables

picked app deploy and picked app dev read PICKED_APP_PRIVATE_KEY and PICKED_APP_PUBLIC_KEY to register a public key with the app. See CLI environment variables. An app holds two public keys at most. See Public keys of an app.