ff04c986a1
Co-authored-by: Matt Aitken <matt@mattaitken.com>
70 lines
2.6 KiB
Plaintext
70 lines
2.6 KiB
Plaintext
---
|
|
title: "First-time setup"
|
|
description: "The first time you deploy to a new environment you will need to setup the endpoint for that environment."
|
|
---
|
|
|
|
## 1. Make sure your Client is configured correctly
|
|
|
|
The API Key you use for your `Client` is how we know which environment to run your code against:
|
|
|
|
```ts
|
|
export const client = new TriggerClient({
|
|
id: "nextjs-example",
|
|
//this environment variable should be set to your DEV API Key locally,
|
|
//and your PROD API Key in production
|
|
apiKey: process.env.TRIGGER_API_KEY!,
|
|
});
|
|
```
|
|
|
|
## 2. Include your Jobs in `sideEffects` if needed
|
|
|
|
If your `package.json` does not declare `sideEffects`, you can safely skip this step. Otherwise, include a glob pattern that matches your jobs so that they are not tree shaken away in your production bundle.
|
|
|
|
```json
|
|
// package.json
|
|
{
|
|
"name": "my-app",
|
|
"sideEffects": [
|
|
"./src/jobs/**/*.ts"
|
|
]
|
|
}
|
|
```
|
|
|
|
## 3. Set your environment variables on your server
|
|
|
|
Ensure that your `TRIGGER_API_KEY` (or whatever you've set it to) environment variable is set on your server, to the correct value from the "Environments & API Keys" page in your Trigger.dev dashboard.
|
|
|
|

|
|
|
|
If you've used any other environment variables in your code (like API Keys for other services), make sure they are set on your server too.
|
|
|
|
The exact instructions will vary depending on where you deploy to. Here are the docs links to some popular services:
|
|
|
|
- [Vercel](https://vercel.com/docs/concepts/projects/environment-variables#)
|
|
- [Cloudflare Pages](https://developers.cloudflare.com/pages/platform/functions/bindings/#environment-variables)
|
|
- [Cloudflare Workers](https://developers.cloudflare.com/workers/platform/environment-variables/)
|
|
- [Netlify](https://docs.netlify.com/environment-variables/overview/)
|
|
|
|
## 4. Deploy your code as usual
|
|
|
|
Your Job code lives in your codebase, so you can deploy it as you normally would.
|
|
|
|
## 5. Connect the Endpoint for the first time
|
|
|
|
1. Go to the "Environments & API Keys" page in your Trigger.dev dashboard
|
|

|
|
|
|
2. Click the "Configure" button on the relevant endpoint
|
|

|
|
|
|
3. Enter the URL of your Trigger.dev endpoint
|
|

|
|
|
|
<Info>
|
|
This is the value of the `path` option for the adaptor you're using. For
|
|
Next.js, this would usually be `https://yourdomain.com/api/trigger`.
|
|
</Info>
|
|
|
|
4. Click "Save". This will automatically connect, test your endpoint, and register all your Jobs.
|
|

|