Skip to content

Commit f882876

Browse files
committedJun 2, 2023
feat: Add Resend with Vercel Edge Functions example
0 parents  commit f882876

File tree

7 files changed

+688
-0
lines changed

7 files changed

+688
-0
lines changed
 

‎.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env
2+
.next
3+
.vercel
4+
node_modules

‎README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Resend with Vercel Edge Functions
2+
3+
This example shows how to use Resend with [Vercel Edge Functions](https://vercel.com).
4+
5+
## Instructions
6+
7+
1. Install dependencies:
8+
9+
```sh
10+
npm install
11+
# or
12+
yarn
13+
```
14+
15+
2. Run Next.js locally:
16+
17+
```sh
18+
npm run dev
19+
```
20+
21+
3. Open URL in the browser:
22+
23+
```
24+
http://localhost:3000/api/send
25+
```

‎app/api/send/route.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { NextResponse } from 'next/server';
2+
3+
export const runtime = 'edge';
4+
export const dynamic = 'force-dynamic';
5+
6+
const RESEND_API_KEY = 're_123456789';
7+
8+
export async function POST() {
9+
const res = await fetch('https://api.resend.com/emails', {
10+
method: 'POST',
11+
headers: {
12+
'Content-Type': 'application/json',
13+
'Authorization': `Bearer ${RESEND_API_KEY}`
14+
},
15+
body: JSON.stringify({
16+
from: 'onboarding@resend.dev',
17+
to: 'delivered@resend.dev',
18+
subject: 'hello world',
19+
html: '<strong>it works!</strong>',
20+
})
21+
});
22+
23+
if (res.ok) {
24+
const data = await res.json();
25+
return NextResponse.json(data);
26+
}
27+
}

‎next-env.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

‎package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "with-vercel-edge-functions",
3+
"private": true,
4+
"scripts": {
5+
"dev": "next dev"
6+
},
7+
"dependencies": {
8+
"next": "^13.4.3",
9+
"react": "^18.2.0",
10+
"react-dom": "^18.2.0",
11+
"resend": "^0.14.0"
12+
},
13+
"devDependencies": {
14+
"@types/node": "20.2.1",
15+
"@types/react": "18.2.6",
16+
"typescript": "5.0.4"
17+
}
18+
}

‎tsconfig.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
9+
"allowJs": true,
10+
"skipLibCheck": true,
11+
"strict": false,
12+
"forceConsistentCasingInFileNames": true,
13+
"noEmit": true,
14+
"incremental": true,
15+
"esModuleInterop": true,
16+
"module": "esnext",
17+
"resolveJsonModule": true,
18+
"moduleResolution": "node",
19+
"isolatedModules": true,
20+
"jsx": "preserve",
21+
"plugins": [
22+
{
23+
"name": "next"
24+
}
25+
]
26+
},
27+
"include": [
28+
"next-env.d.ts",
29+
"**/*.ts",
30+
"**/*.tsx",
31+
".next/types/**/*.ts"
32+
],
33+
"exclude": [
34+
"node_modules"
35+
]
36+
}

0 commit comments

Comments
 (0)
Please sign in to comment.