-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d98186
commit ce02241
Showing
21 changed files
with
377 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
{ | ||
"plugins": ["prettier-plugin-tailwindcss"], | ||
"bracketSameLine": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +0,0 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
# or | ||
bun dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. | ||
|
||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
import { render } from "@react-email/render" | ||
import { render } from "@react-email/render"; | ||
|
||
import WelcomeTemplate from "../../../emails" | ||
import WelcomeTemplate from "../../../emails"; | ||
|
||
import { Resend } from "resend" | ||
import { NextRequest, NextResponse } from "next/server" | ||
import { Redis } from "@upstash/redis" | ||
import { Ratelimit } from "@upstash/ratelimit" | ||
import { Resend } from "resend"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { Redis } from "@upstash/redis"; | ||
import { Ratelimit } from "@upstash/ratelimit"; | ||
|
||
const resend = new Resend(process.env.RESEND_API_KEY) | ||
const resend = new Resend(process.env.RESEND_API_KEY); | ||
|
||
const redis = new Redis({ | ||
url: process.env.UPSTASH_REDIS_REST_URL, | ||
token: process.env.UPSTASH_REDIS_REST_TOKEN, | ||
}) | ||
}); | ||
|
||
const ratelimit = new Ratelimit({ | ||
redis, | ||
limiter: Ratelimit.fixedWindow(3, "1 m"), | ||
}) | ||
// 2 requests per minute from the same IP address in a sliding window of 1 minute duration which means that the window slides forward every second and the rate limit is reset every minute for each IP address. | ||
limiter: Ratelimit.slidingWindow(2, "1 m"), | ||
}); | ||
|
||
export async function POST(request: NextRequest, response: NextResponse) { | ||
const ip = request.ip ?? "127.0.0.1" | ||
const ip = request.ip ?? "127.0.0.1"; | ||
|
||
const result = await ratelimit.limit(ip) | ||
const result = await ratelimit.limit(ip); | ||
|
||
if (!result.success) { | ||
return Response.json( | ||
|
@@ -31,27 +32,29 @@ export async function POST(request: NextRequest, response: NextResponse) { | |
}, | ||
{ | ||
status: 429, | ||
} | ||
) | ||
}, | ||
); | ||
} | ||
|
||
const { email, firstname } = await request.json() | ||
const { email, firstname } = await request.json(); | ||
|
||
const { data, error } = await resend.emails.send({ | ||
from: "morph2json <[email protected]>", | ||
to: [email], | ||
subject: "Thankyou for waitlisting morph2json!", | ||
reply_to: "[email protected]", | ||
html: render(WelcomeTemplate({ userFirstname: firstname })), | ||
}) | ||
}); | ||
|
||
// const { data, error } = { data: true, error: null } | ||
|
||
if (error) { | ||
return NextResponse.json(error) | ||
return NextResponse.json(error); | ||
} | ||
|
||
if (!data) { | ||
return NextResponse.json({ message: "Failed to send email" }) | ||
return NextResponse.json({ message: "Failed to send email" }); | ||
} | ||
|
||
return NextResponse.json({ message: "Email sent successfully" }) | ||
return NextResponse.json({ message: "Email sent successfully" }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.