An open API service indexing awesome lists of open source software.

https://github.com/biomathcode/sass-waitlist-cloudflare

Sass Wailtlist template build with hono, astro, and cloudflare
https://github.com/biomathcode/sass-waitlist-cloudflare

astro cloudflare hono template waitlist

Last synced: 27 days ago
JSON representation

Sass Wailtlist template build with hono, astro, and cloudflare

Awesome Lists containing this project

README

          

# SaaS Waitlist Template

Waitlist Template Preview

Astro frontend + Hono API on Cloudflare Workers with:

- Waitlist signup form
- D1 persistence through Drizzle ORM
- Email verification via Resend
- Notion sync on successful email confirmation
- Edge rate limiting

## Architecture

```text
Browser
-> Astro page (src/client)
-> /api/* (Vite proxy in dev, same-origin in production)
-> Hono Worker (src/server/index.ts)
-> Cloudflare D1 (DB binding)
-> Resend API (confirmation emails)
-> Notion API (store confirmed users)
-> Cloudflare Rate Limiter (MY_RATE_LIMITER)
```

## Signup + Confirmation Flow

1. `POST /api/signup` validates payload with Zod.
2. Worker checks duplicate email in D1.
3. New subscriber is inserted with a `confirmationToken`.
4. Resend sends email containing `/api/confirm?token=...`.
5. `GET /api/confirm` marks subscriber as verified and clears token.
6. Confirmed subscriber is pushed to Notion (`addSubscriberToNotion`).

## Key Files

```text
src/
client/
components/Waitlist.astro # UI + browser-side fetch calls
pages/index.astro # Waitlist page composition
server/
index.ts # Hono routes + csrf + rate limiting
db/
schema.ts # Drizzle table definition
queries.ts # DB operations + Notion side effect
lib/
email.ts # Resend email sender
notion.ts # Notion API client
middleware/auth.ts # Optional Cloudflare Access JWT middleware
drizzle/ # SQL migrations
wrangler.example.jsonc # Safe Wrangler template (no real secrets)
.env.example # Safe local env template (no real secrets)
```

## API Endpoints

| Method | Path | Description |
| ------ | ------------------------ | ------------------------------------------------------- |
| `GET` | `/api/health` | Worker health check |
| `GET` | `/api/subscriber-count` | Returns total subscriber count |
| `POST` | `/api/signup` | Creates pending subscriber and sends confirmation email |
| `GET` | `/api/confirm?token=...` | Confirms email and pushes user to Notion |

## Configuration

Use these variables in `wrangler.jsonc`, `.env`, or `.dev.vars` based on environment:

| Variable | Required | Purpose |
| ---------------------- | -------- | ---------------------------------------- |
| `ENVIRONMENT` | Yes | `development`, `staging`, `production` |
| `RESEND_API_KEY` | Yes | Resend API auth key |
| `RESEND_FROM_EMAIL` | No | Sender identity for confirmation email |
| `NOTION_TOKEN` | Yes | Notion integration token |
| `NOTION_DATASOURCE_ID` | Yes | Notion data source ID |
| `CSRF_ALLOWED_ORIGINS` | No | Comma-separated allowed origins for CSRF |
| `CF_ACCESS_DOMAIN` | Optional | Cloudflare Access team domain |
| `POLICY_AUD` | Optional | Cloudflare Access audience |

Notes:
- `CSRF_ALLOWED_ORIGINS` defaults to strict same-origin checks when omitted.
- `middleware/auth.ts` is available, but not mounted by default in `src/server/index.ts`.

## Local Development

1. Install dependencies:

```bash
bun install
```

2. Create local config from templates:

```bash
cp .env.example .env
cp .env.example .dev.vars
cp wrangler.example.jsonc wrangler.jsonc
```

3. Replace all `REPLACE_WITH_*` placeholders with real values.

4. Apply local D1 migrations:

```bash
bun run db:migrate:local
```

5. Start Astro + Worker together:

```bash
bun run dev
```

## Deploy

Run build + deploy:

```bash
bun run deploy:staging
bun run deploy:prod
```

Dry-run first (recommended):

```bash
bun run dryrun:staging
bun run dryrun:prod
```

If you prefer not to store secrets in `wrangler.jsonc`, use Wrangler secrets:

```bash
wrangler secret put RESEND_API_KEY --env staging
wrangler secret put NOTION_TOKEN --env staging
wrangler secret put RESEND_API_KEY --env production
wrangler secret put NOTION_TOKEN --env production
```

## Database + Tests

- Generate migrations: `bun run db:generate`
- Run tests: `bun run test`

## Security Checklist

- Keep `.env`, `.dev.vars`, and `wrangler.jsonc` out of git.
- Commit only `.env.example` and `wrangler.example.jsonc`.
- Never commit real API tokens.