Skip to content

Commit 09aaa80

Browse files
committed
Improvements to the Remix guide
1 parent fd9a748 commit 09aaa80

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

docs/guides/frameworks/remix.mdx

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ For more information on authenticating with Trigger.dev, see the [API keys page]
4040

4141
<Step title="Create an API route">
4242

43-
Create a new file called `api.trigger.ts` (or `api.trigger.js`) in the `app/routes` directory like this: `app/routes/api.trigger.ts`.
43+
Create a new file called `api.hello-world.ts` (or `api.hello-world.js`) in the `app/routes` directory like this: `app/routes/api.hello-world.ts`.
4444

4545
</Step>
4646

4747
<Step title="Add your task">
4848

49-
Add this code to your `api.trigger.ts` file which imports your task:
49+
Add this code to your `api.hello-world.ts` file which imports your task:
5050

51-
```ts
51+
```ts app/routes/api.hello-world.ts
5252
import type { helloWorldTask } from "../../src/trigger/example";
5353
import { tasks } from "@trigger.dev/sdk/v3";
5454

@@ -78,12 +78,44 @@ For more information on authenticating with Trigger.dev, see the [API keys page]
7878

7979
<DeployingYourTask/>
8080

81-
## Deploying Remix to Vercel Edge Functions
81+
## Deploying to Vercel Edge Functions
8282

83-
There are a few extra steps to follow to deploy your Remix app to Vercel Edge Functions.
83+
Before we start, it's important to note that:
84+
- We'll be using a type-only import for the task to ensure compatibility with the edge runtime.
85+
- The `@trigger.dev/sdk/v3` package supports the edge runtime out of the box.
86+
87+
There are a few extra steps to follow to deploy your `/api/hello-world` API endpoint to Vercel Edge Functions.
8488

8589
<Steps>
8690

91+
<Step title="Update your API route">
92+
93+
Update your API route to use the `runtime: "edge"` option and change it to an `action()` so we can trigger the task from a curl request later on.
94+
95+
```ts app/routes/api.hello-world.ts
96+
import { tasks } from "@trigger.dev/sdk/v3";
97+
import type { helloWorldTask } from "../../src/trigger/example";
98+
// 👆 **type-only** import
99+
100+
// include this at the top of your API route file
101+
export const config = {
102+
runtime: "edge",
103+
};
104+
export async function action({ request }: { request: Request }) {
105+
// This is where you'd authenticate the request
106+
const payload = await request.json();
107+
const handle = await tasks.trigger<typeof helloWorldTask>(
108+
"hello-world",
109+
payload
110+
);
111+
return new Response(JSON.stringify(handle), {
112+
headers: { "Content-Type": "application/json" },
113+
});
114+
}
115+
```
116+
117+
</Step>
118+
87119
<Step title="Update the Vercel configuration">
88120

89121
Create or update the `vercel.json` file with the following:
@@ -100,7 +132,7 @@ Create or update the `vercel.json` file with the following:
100132

101133
</Step>
102134

103-
<Step title="Update `package.json` scripts">
135+
<Step title="Update package.json scripts">
104136

105137
Update your `package.json` to include the following scripts:
106138

@@ -148,7 +180,15 @@ Once you've added the environment variable, deploy your project to Vercel.
148180

149181
<Step title="Test your task in production">
150182

151-
After deployment, visit your Vercel deployment URL followed by `/api/trigger` (e.g., `https://your-app.vercel.app/api/trigger`) to test the Trigger.dev task in production.
183+
After deployment, you can test your task in production by running this curl command:
184+
185+
```bash
186+
curl -X POST https://your-app.vercel.app/api/hello-world \
187+
-H "Content-Type: application/json" \
188+
-d '{"name": "James"}'
189+
```
190+
191+
This sends a POST request to your API endpoint with a JSON payload.
152192

153193
</Step>
154194

0 commit comments

Comments
 (0)