You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/deploy-environment-variables.mdx
+64-1Lines changed: 64 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,18 @@ You can edit an environment variable's values. You cannot edit the key name, you
66
66
67
67
</Steps>
68
68
69
+
## Local development
70
+
71
+
When running `npx trigger.dev dev`, the CLI automatically loads environment variables from these files in order (later files override any duplicate keys from earlier ones):
72
+
73
+
-`.env`
74
+
-`.env.development`
75
+
-`.env.local`
76
+
-`.env.development.local`
77
+
-`dev.vars`
78
+
79
+
These variables are available to your tasks via `process.env`. You don't need to use the `--env-file` flag for this automatic loading.
80
+
69
81
## In your code
70
82
71
83
You can use our SDK to get and manipulate environment variables. You can also easily sync environment variables from another service into Trigger.dev.
@@ -360,4 +372,55 @@ This will read your .env.production file using dotenvx and sync the variables to
360
372
361
373
- Trigger.dev does not automatically detect .env.production or dotenvx files
362
374
- You can paste them manually into the dashboard
363
-
- Or sync them automatically using a build extension
375
+
- Or sync them automatically using a build extension
376
+
377
+
## Multi-tenant applications
378
+
379
+
If you're building a multi-tenant application where each tenant needs different environment variables (like tenant-specific API keys or database credentials), you don't need a separate project for each tenant. Instead, use a single project and load tenant-specific secrets at runtime.
380
+
381
+
<Note>
382
+
This is different from [syncing environment variables at deploy time](#sync-env-vars-from-another-service).
383
+
Here, secrets are loaded dynamically during task execution, not synced to Trigger.dev's environment variables.
384
+
</Note>
385
+
386
+
### Recommended approach
387
+
388
+
Use a secrets service (Infisical, AWS Secrets Manager, HashiCorp Vault, etc.) to store tenant-specific secrets, then retrieve them at the start of each task run based on the tenant identifier in your payload or context.
389
+
390
+
**Important:** Never pass secrets in the task payload, as payloads are logged and visible in the dashboard.
// Your task logic using the tenant-specific secret
412
+
// ...
413
+
},
414
+
});
415
+
```
416
+
417
+
You can use any secrets service - see the [sync env vars section](#sync-env-vars-from-another-service) for an example with Infisical.
418
+
419
+
### Benefits
420
+
421
+
-**Single codebase** - Deploy once, works for all tenants
422
+
-**Secure** - Secrets never appear in payloads or logs
423
+
-**Scalable** - No project limit constraints
424
+
-**Flexible** - Easy to add new tenants without redeploying
425
+
426
+
This approach allows you to support unlimited tenants with a single Trigger.dev project, avoiding the [project limit](/limits#projects) while maintaining security and separation of tenant data.
description: "This example demonstrates how to use Hookdeck to receive webhooks and trigger Trigger.dev tasks."
5
+
---
6
+
7
+
## Overview
8
+
9
+
This example shows how to use [Hookdeck](https://hookdeck.com) as your webhook infrastructure to trigger Trigger.dev tasks. Hookdeck receives webhooks from external services, and forwards them directly to the Trigger.dev API. This gives you the best of both worlds: Hookdeck's webhook management, logging, and replay capabilities, combined with Trigger.dev's reliable task execution.
10
+
11
+
## Key features
12
+
13
+
- Use Hookdeck as your webhook endpoint for external services
14
+
- Hookdeck forwards webhooks directly to Trigger.dev tasks via the API
15
+
- All webhooks are logged and replayable in Hookdeck
16
+
17
+
## Setting up Hookdeck
18
+
19
+
You'll configure everything in the [Hookdeck dashboard](https://dashboard.hookdeck.com). No code changes needed in your app.
20
+
21
+
### 1. Create a destination
22
+
23
+
In Hookdeck, create a new [destination](https://hookdeck.com/docs/destinations) with the following settings:
24
+
25
+
-**URL**: `https://api.trigger.dev/api/v1/tasks/<task-id>/trigger` (replace `<task-id>` with your task ID)
26
+
-**Method**: POST
27
+
-**Authentication**: Bearer token (use your `TRIGGER_SECRET_KEY` from Trigger.dev)
28
+
29
+
### 2. Add a transformation
30
+
31
+
Create a [transformation](https://hookdeck.com/docs/transformations) to wrap the webhook body in the `payload` field that Trigger.dev expects:
32
+
33
+
```javascript
34
+
addHandler("transform", (request, context) => {
35
+
request.body= { payload: { ...request.body } };
36
+
return request;
37
+
});
38
+
```
39
+
40
+
### 3. Create a connection
41
+
42
+
Create a [connection](https://hookdeck.com/docs/connections) that links your source (where webhooks come from) to the destination and transformation you created above.
43
+
44
+
## Task code
45
+
46
+
This task will be triggered when Hookdeck forwards a webhook to the Trigger.dev API.
47
+
48
+
```ts trigger/webhook-handler.ts
49
+
import { task } from"@trigger.dev/sdk";
50
+
51
+
exportconst webhookHandler =task({
52
+
id: "webhook-handler",
53
+
run: async (payload:Record<string, unknown>) => {
54
+
// The payload contains the original webhook data from the external service
55
+
console.log("Received webhook:", payload);
56
+
57
+
// Add your custom logic here
58
+
},
59
+
});
60
+
```
61
+
62
+
## Testing your setup
63
+
64
+
To test everything is working:
65
+
66
+
1. Set up your destination, transformation, and connection in [Hookdeck](https://dashboard.hookdeck.com)
67
+
2. Send a test webhook to your Hookdeck source URL (use the Hookdeck Console or cURL)
68
+
3. Check the Hookdeck dashboard to verify the webhook was received and forwarded
69
+
4. Check the [Trigger.dev dashboard](https://cloud.trigger.dev) to see the successful run of your task
70
+
71
+
For more information on setting up Hookdeck, refer to the [Hookdeck Documentation](https://hookdeck.com/docs).
0 commit comments