How to handle environment variables in ShipThing.
keys.ts
file, which exports an keys
object that contains all validated environment variables, separated into server
and client
variables.
These keys are then composed together into a single environment variable file for the app, located in an env.ts
file in the root of the app.
.env.example
file is copied to a real environment variable file in each Next.js application and some packages. From here, you can fill in the variables yourself.
app/.env.local
- The app’s environment variables.web/.env.local
- The web app’s environment variables.api/.env.local
- The API app’s environment variables.packages/database/.env
- The database package’s environment variables.packages/internationalization/.env.local
- The internationalization package’s environment variables.NEXT_PUBLIC_APP_URL
, NEXT_PUBLIC_WEB_URL
, and NEXT_PUBLIC_API_URL
, you do not need to modify them locally, but should replace them with the URLs of your individual applications when you deploy them.
*CLERK*
, you should use the test key locally and the production key when deploying.
keys.ts
file contains the validation rules for each environment variable. These are used to validate the environment variables in the .env.local
files. You can inspect these files to see the validation rules for each variable.
sec_
, you should validate it as z.string().min(1).startsWith('sec_')
. This will not only make your intent clearer to anyone reading your code, but will also help prevent errors at runtime.SENTRY_
are automatically added to a Vercel project when you add the Sentry integration from the Vercel Marketplace. Additionally, VERCEL_PROJECT_PRODUCTION_URL
is a very handy environment variable that refers to the “production” URL to which this project is deployed on Vercel.
VERCEL_PROJECT_PRODUCTION_URL
, when you deploy to vercel, it defaults to the domain you deployed for the application.env.local
files across the projectserver
or client
object in the relevant package’s keys.ts
file.