Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 84 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,86 @@
# notion-waitlist

[Vercel's Next.js Waitlist with Notion CMS](https://github.com/lakshaybhushan/nextjs-notion-waitlist-template) on
**Cloudflare Workers**, deployed by [Orun](https://github.com/sourceplane/orun) to stage
and prod on every merge, and then packaged as an Orun baseline.

This commit is the repository's frame: `intent.yaml` (with the placeholder
workspace `ws_CHANGE_ME`, so CI plans nothing until it is linked), the Orun
CI workflow, the shared TypeScript and ESLint configuration, and the spec
index. The work is tracked as an epic under [`specs/epics`](specs/epics/README.md).
Lakshay Bhushan's [Next.js waitlist with Notion as CMS](https://github.com/lakshaybhushan/nextjs-notion-waitlist-template)
([lakshaybhushan/nextjs-notion-waitlist-template](https://github.com/lakshaybhushan/nextjs-notion-waitlist-template),
Vercel's "Next.js Waitlist with Notion CMS" template, demo at
https://nextjs-notion-waitlist.vercel.app) — an animated one-page waitlist
that saves each signup to a Notion database and sends a React Email welcome
through Resend, rate-limited per visitor — running on **Cloudflare Workers +
Static Assets** through [`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare), deployed by
[Orun](https://github.com/sourceplane/orun) to stage and prod on every merge.
Packaging it as an Orun baseline is the next milestone (NW2).

The template's code is the code. What the port adds is the Workers build,
the monorepo wrapper, a test package and the deploy contract; what it
changes is what Workers and a fresh, unattended deployment force: Upstash's
rate limit is Cloudflare's own Workers Rate Limiting binding (and covers
both signup routes, not only the email), Notion's and Resend's keys are Orun
secrets the owner stores after the build, handed to the Worker as Worker
secrets, a signup is told the waitlist is not connected yet until they are,
the email is sent from the owner's own address (`RESEND_FROM`) rather than
the template author's, Figtree is self-hosted, and the "Use this template"
button is the site's own source link. See
[`specs/epics/notion-waitlist`](specs/epics/notion-waitlist/README.md)
for the design, the milestones and the as-built status, including every
departure.

## What is here (the site)

| Surface | Where |
|---|---|
| The site's name, source link and origin | `apps/web/app/site.ts` |
| The waitlist page (the template's header, call to action, form, logos, footer and particles) | `apps/web/app/page.tsx`, `apps/web/components` |
| `/api/mail` (the welcome email), `/api/notion` (the row), `/api/health` (the deploy's smoke) | `apps/web/app/api` |
| Whether Notion and Resend are connected, and the rate limit both routes take | `apps/web/lib/waitlist.ts` |
| The welcome email (React Email) | `apps/web/emails/index.tsx` |
| The rate-limit binding (`SIGNUP_LIMITER`, two per sixty seconds) | `apps/web/wrangler.jsonc` |
| The Worker-secret push (Notion's and Resend's keys) | `tooling/wire/worker-secrets.mjs` |
| Workers build and deploy contract | `apps/web/next.config.ts`, `open-next.config.ts`, `wrangler.jsonc`, `component.yaml` |
| Tests | `tests/web` (vitest) |

## Getting started

```bash
pnpm install
pnpm typecheck
pnpm lint
pnpm test
pnpm build # next build + opennextjs-cloudflare build → apps/web/.open-next
```

The build needs neither Notion nor Resend: their keys are read by the Worker
per request. With an integration's secret, a database id, a Resend key and a
sender in `apps/web/.env.local` (`apps/web/.env.example`),
`pnpm --filter @app/web dev` takes real signups; `pnpm --filter @app/web
preview` serves the built Worker with the same keys from `apps/web/.dev.vars`.

## How it maps to Vercel

| Vercel | Here |
|---|---|
| Next.js hosting on Vercel's runtime | One Cloudflare Worker (`.open-next/worker.js`) + Static Assets, built by `next build --webpack` (Turbopack's per-route server chunks put the Worker at 2.97 MiB gzipped, against Workers Free's 3 MiB; webpack's are 1.48 MiB) |
| Upstash Redis rate limit (`Ratelimit.slidingWindow(2, "1 m")`, keyed on `request.ip`) on the email route | Workers Rate Limiting (`SIGNUP_LIMITER`: two per sixty seconds, a fixed window), keyed on the site's host, the route and `CF-Connecting-IP`, on BOTH the email and the Notion route |
| `NOTION_SECRET`, `NOTION_DB`, `RESEND_API_KEY` as project env vars | Orun secrets per environment the owner stores (and `RESEND_FROM`), read by the build as optional refs and handed to the Worker as Worker secrets; no bundle holds one |
| Missing keys (the Resend client throws on import, every signup fails) | The not-connected site: the page renders, a signup gets a 503 naming the keys it lacks, and the page says the waitlist is not connected yet |
| The template author's sender (`hello@waitlist.lakshb.dev`), reply-to and logo URL in the email | `RESEND_FROM`, no reply-to (replies go to the sender), the logo from the site's own origin |
| `next/font/google` (Figtree) | Figtree self-hosted from `@fontsource-variable/figtree` (OFL-1.1) |
| `@vercel/analytics` | Dropped |
| The "Upstash" and "Vercel" tiles under "Powered by" | Dropped (the port uses neither); the grid is two by two |
| `app/opengraph-image.png`, `app/twitter-image.png` beside a hand-written `og:image` meta | The same images served from `public/` and named in `metadata` on `metadataBase` (as file conventions Next compiles each 1.3 MB image into the Worker) |
| Hard-coded `vercel.app` `og:url` | `NEXT_PUBLIC_SITE_URL`, set per environment by the deploy |
| "Use this template" (fork the template on GitHub) | The site's own source link; `orun new --blueprint repo-blueprint.yaml` is the clone — a new repository, branded, deployed |
| Deploy on push | Orun deploys `<repo>-web-{stage,prod}` on merge to `main` (`apps/web/component.yaml`), smoke-tested |

## Licence

The template carries no licence file and GitHub records none. Its README's
"License" section allows personal and commercial use and modification, and
asks commercial users to consider supporting its author; that section is
the only grant, and this repository keeps the template's credit (the
footer's "Brought to you by" and the links above).

## CI

| Workflow | What it runs | Ships to a site |
|---|---|---|
| `ci.yml` | the Orun pipeline, and the only workflow a site carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (the site built and dry-deployed per environment; the tests' `quick-check` lane installs and checks the package, it does not run them), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone is the check; a merge deploys stage → prod. It plans nothing while `intent.yaml` names the placeholder workspace `ws_CHANGE_ME`, as this repository does. A manual run (Orunbase's Deploy button, or Run workflow on `main`) plans the environment and components it names under the push-to-main trigger, so they deploy as a merge deploys them | yes |
20 changes: 20 additions & 0 deletions apps/web/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Notion: the integration (https://www.notion.so/profile/integrations) whose
# secret writes each signup, and the id of the database it writes to — the
# database shared with the integration, with a `Name` (title) and an `Email`
# (email) property. In a deployed environment they are the NOTION_SECRET and
# NOTION_DB Orun secrets (README → Connect Notion and Resend); never commit
# them.
NOTION_SECRET=
NOTION_DB=

# Resend: the API key that sends the welcome email, and the sender it sends
# from — an address on a domain verified in Resend, e.g.
# "Your Name <hello@waitlist.your-domain.com>". The RESEND_API_KEY and
# RESEND_FROM Orun secrets in a deployed environment.
RESEND_API_KEY=
RESEND_FROM=

# Optional. The site's public origin (the Open Graph image's absolute URL,
# the email's logo); the Orun build sets it to the environment's SITE_URL or
# Worker URL.
NEXT_PUBLIC_SITE_URL=http://localhost:3000
9 changes: 9 additions & 0 deletions apps/web/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- BEGIN:nextjs-agent-rules -->

# This is NOT the Next.js you know

This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.

This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.

<!-- END:nextjs-agent-rules -->
29 changes: 29 additions & 0 deletions apps/web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# apps/web — the site

The Next.js waitlist with Notion as CMS
([lakshaybhushan/nextjs-notion-waitlist-template](https://github.com/lakshaybhushan/nextjs-notion-waitlist-template)),
running on Cloudflare Workers + Static Assets:

- One animated page: the header, the call to action, the name and email
form, the "Powered by" logos, the footer and the particles
(`app/page.tsx`, `components/`)
- `/api/mail` sends the React Email welcome (`emails/index.tsx`) through
Resend; `/api/notion` adds the signup to a Notion database
- Both routes take the Worker's `SIGNUP_LIMITER` rate limit, two a minute
per visitor (`wrangler.jsonc`, `lib/waitlist.ts`)
- Tailwind 3, shadcn/ui, framer-motion, Figtree self-hosted

Notion and Resend are connected when the Worker holds their keys
(`lib/waitlist.ts`); until then a signup is told the waitlist is not
connected yet. The site's name and the repository its header links to are
in `app/site.ts`.

```bash
cp .env.example .env.local # and fill in the four keys
pnpm dev # next dev on http://localhost:3000
pnpm build # next build --webpack + opennextjs-cloudflare build → .open-next/
pnpm preview # wrangler dev over the built Worker (the keys from .dev.vars)
```

How it is deployed — per environment, on merge to `main` — is the
repository's README and `component.yaml` beside this file.
22 changes: 22 additions & 0 deletions apps/web/app/api/health/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { getCloudflareContext } from "@opennextjs/cloudflare";
import { NextResponse } from "next/server";
import { notionConfig, resendConfig } from "@/lib/waitlist";

// What every deploy's smoke test reads: whether the Worker has what a signup
// needs of its own — the SIGNUP_LIMITER rate-limit binding wrangler.jsonc
// declares — and whether Notion and Resend are connected (their keys are the
// owner's to store, so either answer is ok). Names only — never a value.
export const dynamic = "force-dynamic";

export function GET() {
const limiter = Boolean(getCloudflareContext().env.SIGNUP_LIMITER);
return NextResponse.json(
{
ok: limiter,
rateLimit: limiter ? "bound" : "missing",
notion: notionConfig() ? "connected" : "not-connected",
resend: resendConfig() ? "connected" : "not-connected",
},
{ status: limiter ? 200 : 503 },
);
}
37 changes: 37 additions & 0 deletions apps/web/app/api/mail/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { render } from "@react-email/render";
import { getCloudflareContext } from "@opennextjs/cloudflare";

import WelcomeTemplate from "../../../emails";

import { Resend } from "resend";
import { NextRequest, NextResponse } from "next/server";
import { allowed, notConnected, resendConfig, tooManyRequests } from "@/lib/waitlist";

export async function POST(request: NextRequest) {
const config = resendConfig();
if (!config) return notConnected("Resend");
// 2 requests per minute from the same IP address (lib/waitlist.ts).
if (!(await allowed(getCloudflareContext().env.SIGNUP_LIMITER, "mail", request))) {
return tooManyRequests();
}

const { email, firstname } = await request.json();

const resend = new Resend(config.apiKey);
const { data, error } = await resend.emails.send({
from: config.from,
to: [email],
subject: "Thankyou for wailisting the Next.js + Notion CMS template!",
html: await render(WelcomeTemplate({ userFirstname: firstname })),
});

if (error) {
return NextResponse.json(error, { status: 502 });
}

if (!data) {
return NextResponse.json({ message: "Failed to send email" }, { status: 502 });
}

return NextResponse.json({ message: "Email sent successfully" });
}
55 changes: 55 additions & 0 deletions apps/web/app/api/notion/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Client } from "@notionhq/client";
import { getCloudflareContext } from "@opennextjs/cloudflare";
import { NextResponse } from "next/server";
import { allowed, notConnected, notionConfig, tooManyRequests } from "@/lib/waitlist";

export async function POST(request: Request) {
const config = notionConfig();
if (!config) return notConnected("Notion");
if (!(await allowed(getCloudflareContext().env.SIGNUP_LIMITER, "notion", request))) {
return tooManyRequests();
}

const body = await request.json();
try {
const notion = new Client({
auth: config.secret,
baseUrl: config.baseUrl,
// The Worker's own fetch. The client's default is node-fetch, and it
// calls whatever it is given as a method of itself, which the Workers
// runtime refuses for its native fetch ("Illegal invocation"), so the
// call goes through a plain function.
fetch: ((url: string, init: RequestInit) => fetch(url, init)) as never,
});
const response = await notion.pages.create({
parent: {
database_id: `${config.database}`,
},
properties: {
Email: {
type: "email",
email: body?.email,
},
Name: {
type: "title",
title: [
{
type: "text",
text: {
content: body?.name,
},
},
],
},
},
});

if (!response) {
throw new Error("Failed to add email to Notion");
}

return NextResponse.json({ success: true }, { status: 200 });
} catch {
return NextResponse.json({ success: false }, { status: 500 });
}
}
Binary file added apps/web/app/favicon.ico
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions apps/web/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;

--card: 0 0% 100%;
--card-foreground: 240 10% 3.9%;

--popover: 0 0% 100%;
--popover-foreground: 240 10% 3.9%;

--primary: 240 5.9% 10%;
--primary-foreground: 0 0% 98%;

--secondary: 240 4.8% 95.9%;
--secondary-foreground: 240 5.9% 10%;

--muted: 240 4.8% 95.9%;
--muted-foreground: 240 3.8% 46.1%;

--accent: 240 4.8% 95.9%;
--accent-foreground: 240 5.9% 10%;

--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;

--border: 240 5.9% 90%;
--input: 240 5.9% 90%;
--ring: 240 10% 3.9%;

--radius: 0.5rem;
}

.dark {
--background: 240 10% 3.9%;
--foreground: 0 0% 98%;

--card: 240 10% 3.9%;
--card-foreground: 0 0% 98%;

--popover: 240 10% 3.9%;
--popover-foreground: 0 0% 98%;

--primary: 0 0% 98%;
--primary-foreground: 240 5.9% 10%;

--secondary: 240 3.7% 15.9%;
--secondary-foreground: 0 0% 98%;

--muted: 240 3.7% 15.9%;
--muted-foreground: 240 5% 64.9%;

--accent: 240 3.7% 15.9%;
--accent-foreground: 0 0% 98%;

--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;

--border: 240 3.7% 15.9%;
--input: 240 3.7% 15.9%;
--ring: 240 4.9% 83.9%;
}
}

@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}

body {
::selection {
@apply bg-accent text-yellow-200;
}
}
Loading
Loading