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
5 changes: 5 additions & 0 deletions .dev.vars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Local Worker secrets for `mise run dev-worker`. Copy to .dev.vars (git-ignored).
# Turnstile's always-pass test secret; pair it with the test sitekey 1x00000000000000000000AA.
TURNSTILE_SECRET=1x0000000000000000000000000000000AA
# A Slack incoming webhook for testing. Leave empty to have every delivery fail (rows stay in local D1).
SLACK_WEBHOOK_URL=
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Public client-side identifiers — injected at build time.
# These ARE visible in the shipped HTML; this file documents them, it does not hide them.
PUBLIC_FORMSPREE_ID=your-formspree-form-id
PUBLIC_HCAPTCHA_SITEKEY=your-hcaptcha-sitekey
# Public client-side identifier, injected at build time. It IS visible in the shipped HTML.
# Production uses the MTLNOG Turnstile widget; locally you can use Cloudflare's always-pass
# test sitekey 1x00000000000000000000AA (pair it with the test secret in .dev.vars).
PUBLIC_TURNSTILE_SITEKEY=1x00000000000000000000AA
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
cache: npm
- run: npm ci
- run: npm test
- run: npm run typecheck:worker
- name: Build (dummy public env values — real ones live in the Cloudflare Workers project)
run: npm run build
env:
PUBLIC_FORMSPREE_ID: ci-dummy
PUBLIC_HCAPTCHA_SITEKEY: 10000000-ffff-ffff-ffff-000000000001
PUBLIC_TURNSTILE_SITEKEY: 1x00000000000000000000AA
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ dist/
mise.local.toml
.mise.local.toml

# Wrangler local state/cache
# Wrangler local state/cache and local Worker secrets
.wrangler/
.dev.vars
69 changes: 59 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,54 @@ cp .env.example .env # then fill in real values (see below)
mise run dev # installs npm deps if needed, then starts astro dev
```

`mise run dev` serves the pages only. To exercise the contact form end to end, run the Worker locally (see "Contact form" below).

Node version is pinned in `.nvmrc` (Node 22, required by wrangler); mise, nvm, CI, and Cloudflare all read it. `mise tasks` lists the available tasks (`dev`, `test`, `build`, `preview`, `deploy`); each one runs `npm ci` first if the lockfile changed. Plain `npm install` / `npm run …` still works without mise.

## Configuration

Two public, client-side identifiers are injected via env vars (Astro requires the `PUBLIC_` prefix):
| Name | Kind | Where |
|---|---|---|
| `PUBLIC_TURNSTILE_SITEKEY` | Build variable (public, ends up in the HTML) | `.env` locally, Workers Builds settings in production (`0x4AAAAAAFo_cWZB_zA8Phzj`) |
| `TURNSTILE_SECRET` | Worker secret | `.dev.vars` locally, `npx wrangler secret put TURNSTILE_SECRET` in production |
| `SLACK_WEBHOOK_URL` | Worker secret | `.dev.vars` locally, `npx wrangler secret put SLACK_WEBHOOK_URL` in production |
| `DB` | D1 binding (`mtlnog-contact`) | `wrangler.jsonc` |

The build fails fast if `PUBLIC_TURNSTILE_SITEKEY` is missing. Cloudflare's test keys (sitekey `1x00000000000000000000AA`, secret `1x0000000000000000000000000000000AA`) always pass and are what `.env.example`, `.dev.vars.example` and CI use. Secrets never go in the repo.

## Contact form

The home page form (`#invite`) posts JSON to `/api/contact`, handled by `worker/index.ts`. The Worker:

1. checks the fields (rules shared with the form in `src/lib/contact.ts`), a honeypot, and the Turnstile token;
2. stores the submission in D1;
3. posts it to a private Slack channel through the incoming webhook.

| Var | Value |
|---|---|
| `PUBLIC_FORMSPREE_ID` | Formspree form id (the part after `/f/`) |
| `PUBLIC_HCAPTCHA_SITEKEY` | hCaptcha sitekey |
A cron trigger (every 5 minutes) retries Slack deliveries that failed. After 24 hours it gives up on a submission, marks it failed and posts a warning (id and topic only) to Slack. Delivered submissions are deleted after 30 days; failed ones stay until someone handles them.

Topics are `slack`, `sponsorship`, `speaking`, `venue` and `general`. Links like `/en/?type=venue#invite` open the form with that topic selected (`contactHref()` in `src/i18n/routes.ts`).

**Run it locally:**

```bash
cp .dev.vars.example .dev.vars # test Turnstile secret; add a test webhook if you have one
npx wrangler d1 migrations apply DB --local # once, and after schema changes
mise run dev-worker # builds the site, then wrangler dev on http://localhost:8787
```

These appear in the shipped HTML - they are not secrets. Locally they live in `.env` (git-ignored). In production they are set as build variables in the Cloudflare Workers project. The build fails fast if either is missing.
With an empty `SLACK_WEBHOOK_URL`, submissions are stored but every delivery fails; inspect them with `npx wrangler d1 execute DB --local --command "SELECT * FROM submissions"`.

**Check for undelivered submissions in production:**

```bash
npx wrangler d1 execute DB --remote --command "SELECT id, topic, attempts, last_error, failed_at FROM submissions WHERE delivered_at IS NULL"
```

Known blind spot: if the webhook itself breaks (revoked, or the channel archived), the failure warning can't reach Slack either. Submissions are still safe in D1; the query above shows them.

**Database changes:** migrations live in `migrations/` and are applied by hand, before merging the change that needs them: `npx wrangler d1 migrations apply DB --remote`. The Workers Builds deploy does not run them.

**Preview builds** share the production database and secrets. The Turnstile widget only allows mtlnog.org, so previews can't submit unless a preview hostname is added to it; if one is, its test submissions land in the real Slack channel (labelled, and purged like any other).

## Build & test

Expand Down Expand Up @@ -49,22 +85,35 @@ URLs are defined once in `src/i18n/routes.ts`. All page text lives in `src/i18n/

The old `/fr/rencontres/` and `/en/meetings/` URLs redirect to the Events page (`public/_redirects`).

Links like `/en/?type=sponsorship#invite` open the invite form with that option pre-selected.
Links like `/en/?type=sponsorship#invite` open the contact form with that topic pre-selected.

## Deploy (Cloudflare Workers - static assets)

The GitHub repo is connected to Cloudflare via Workers Builds; CF builds and deploys on push to `main`. Deploy config lives in `wrangler.jsonc` (Worker name `mtlnog-org`; the built site in `./dist` is served as static assets).
The GitHub repo is connected to Cloudflare via Workers Builds; CF builds and deploys on push to `main`. Deploy config lives in `wrangler.jsonc` (Worker name `mtlnog-org`): the built site in `./dist` is served as static assets, `/api/*` runs `worker/index.ts`, and a cron trigger runs every 5 minutes.

- **Build command:** `npm run build`
- **Deploy command:** `npx wrangler deploy`
- **Node version:** from `.nvmrc` (22)
- **Build environment variables** (set for Production and Preview): `PUBLIC_FORMSPREE_ID`, `PUBLIC_HCAPTCHA_SITEKEY`
- **Build environment variables** (set for Production and Preview): `PUBLIC_TURNSTILE_SITEKEY`
- **Worker secrets:** `TURNSTILE_SECRET`, `SLACK_WEBHOOK_URL` (set once with `wrangler secret put`)

### First deploy of the contact form

Do these once, before merging the branch that adds the Worker; the deploy fails while `database_id` is still `"local"`:

1. Create the private Slack channel, then the Slack app from `docs/slack-app-manifest.yml` (instructions at the top of the file), and install it to that channel to get the incoming webhook URL.
2. `npx wrangler d1 create mtlnog-contact`, then put the printed `database_id` in `wrangler.jsonc` and commit it.
3. `npx wrangler d1 migrations apply DB --remote`
4. `npx wrangler secret put TURNSTILE_SECRET` and `npx wrangler secret put SLACK_WEBHOOK_URL`
5. Check the Turnstile widget's allowed hostnames include `mtlnog.org`, and set `PUBLIC_TURNSTILE_SITEKEY` in the Workers Builds settings.
6. Merge and push, then send one message per topic on the live site and check each lands in Slack.
7. Remove the old `PUBLIC_FORMSPREE_ID` and `PUBLIC_HCAPTCHA_SITEKEY` build variables.

Deploy manually with `npm run deploy` (requires `wrangler login` or a `CLOUDFLARE_API_TOKEN`).

## CI

`.github/workflows/ci.yml` runs tests + a build (with dummy public env values) on every PR and push to `main`. It does not deploy.
`.github/workflows/ci.yml` runs the tests, a Worker type-check and a build (with the Turnstile test sitekey) on every PR and push to `main`. It does not deploy.

## License

Expand Down
20 changes: 20 additions & 0 deletions docs/slack-app-manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Slack app for the mtlnog.org contact form.
# Create it at https://api.slack.com/apps → Create New App → From an app manifest,
# pick the MTLNOG workspace, paste this file, then Install to Workspace and choose the
# private channel. Copy the webhook URL into the SLACK_WEBHOOK_URL Worker secret.
display_information:
name: MTLNOG Contact Form
description: Posts messages sent through the contact form on mtlnog.org.
background_color: "#08090d"
features:
bot_user:
display_name: MTLNOG site
always_online: false
oauth_config:
scopes:
bot:
- incoming-webhook
settings:
org_deploy_enabled: false
socket_mode_enabled: false
token_rotation_enabled: false
Loading
Loading