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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The repository holds two apps during the rebuild (epic #94):
- **Protocol**: `@atcute/*` packages (client, lexicons, identity resolver)
- **Copy**: British English via Lingui (`web/src/i18n/`)
- **Tests**: Vitest + Testing Library + MSW + axe-core; Playwright for e2e
- **Hosting**: Vercel project `lanyards-next` with Root Directory `web`, serving `lanyards.app` (`PUBLIC_BASE_URL=https://lanyards.app` in Production). `www` and the retired `next.lanyards.app` redirect to it (#154)
- **Hosting**: Vercel project `lanyards` with Root Directory `web`, serving `lanyards.app` (`PUBLIC_BASE_URL=https://lanyards.app` in Production). `www` and the retired `next.lanyards.app` redirect to it (#154)

**Repository root: the legacy Next.js app.** It is frozen and no longer served: `lanyards.app` moved to the new app (#154), and Slice 1c (#103) deletes it. Don't start new work on it.

Expand Down
84 changes: 49 additions & 35 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,61 +121,75 @@ Lanyards' lexicons are published from the `@lanyards.app` account
bsky.social caches a failed lexicon lookup for about 5 minutes, so sign-in may
keep falling back to broad permissions for a few minutes after publishing.

## Deploying the beta (`next.lanyards.app`)
## Deploying (`lanyards.app`)

The app deploys from a **second** Vercel project. The legacy project keeps
serving `lanyards.app` from the repository root until Slice 1c (#103).
The app deploys from the Vercel project **`lanyards`** (team `renderghost`,
Git repo `renderghost/lanyards`), with Root Directory `web`. Until the swap
(#154), that project served the legacy Next.js app from the repository root,
and the beta ran on a second project, `lanyards-next`, at
`next.lanyards.app`.

### 1. Create the Vercel project
### 1. Project settings

In the Vercel dashboard (team `renderghost`): **Add New → Project →** import
`renderghost/lanyards`, then set:

| Setting | Value |
| ----------------- | ----------------------------------------------- |
| Project name | `lanyards-next` |
| Framework preset | Vite |
| Root Directory | `web` |
| Build and output | leave as detected (`web/vercel.json` sets them) |
| Production branch | `main` (Settings → Git, after creation) |
| Setting | Value |
| ------------------------- | -------------------------------------------------- |
| Root Directory | `web` |
| Framework preset | Vite |
| Build, output and install | no overrides (`web/vercel.json` sets build/output) |
| Node.js version | from `engines` in `web/package.json` |
| Production branch | `main` |

Keep **Settings → Environment Variables → "Automatically expose System
Environment Variables"** on, because preview builds use `VERCEL_ENV` and
`VERCEL_BRANCH_URL`.

### 2. Environment variables

| Name | Environment | Value |
| ------------------- | ----------- | --------------------------- |
| `PUBLIC_BASE_URL` | Production | `https://next.lanyards.app` |
| `VITE_POSTHOG_KEY` | — | leave unset during the beta |
| `VITE_POSTHOG_HOST` | — | leave unset during the beta |
| Name | Environment | Value |
| ------------------- | ------------------- | ---------------------------------- |
| `PUBLIC_BASE_URL` | Production only | `https://lanyards.app` |
| `VITE_POSTHOG_KEY` | Production, Preview | optional: analytics is off without |
| `VITE_POSTHOG_HOST` | Production, Preview | optional: defaults to PostHog's EU |

Production builds fail on purpose without `PUBLIC_BASE_URL`, because the
OAuth client metadata is generated from it.
OAuth client metadata is generated from it. Don't set it for Preview:
previews use their own branch URL.

### 3. Domain
### 3. Domains

1. In the project: **Settings → Domains → Add** `next.lanyards.app`.
2. `lanyards.app` uses Cloudflare DNS. Add this record in Cloudflare:
| Domain | Setting |
| ------------------- | --------------------------------------------------------- |
| `lanyards.app` | Production, primary |
| `www.lanyards.app` | Redirect to `lanyards.app`, 308 |
| `next.lanyards.app` | Production, **no** redirect: `web/vercel.json` handles it |

| Type | Name | Target | Proxy status |
| ----- | ------ | ---------------------- | --------------------- |
| CNAME | `next` | `cname.vercel-dns.com` | DNS only (grey cloud) |
`next.lanyards.app` is the retired beta. `web/vercel.json` redirects its
page visits to the same path on `lanyards.app`, and only page visits, so a
copy installed from the beta can still fetch its update. The updated app
then sends it to `lanyards.app` (`src/lib/origin/movedOrigin.ts`). A Vercel
domain redirect would cut installed copies off from their update.

Keep the proxy off so Vercel can issue the certificate.
DNS is on Cloudflare. Keep every Vercel record **DNS only** (grey cloud) so
Vercel can issue certificates. The `_atproto` TXT record verifies the
`@lanyards.app` Bluesky handle, and the `_lexicon` TXT records publish the
lexicons (see above).

### 4. Check the deployment

After the first production deployment from `main`:
After a production deployment from `main`:

```bash
curl -s https://next.lanyards.app/oauth-client-metadata.json
# → JSON whose client_id is https://next.lanyards.app/oauth-client-metadata.json
curl -sI https://next.lanyards.app/oauth-client-metadata.json | grep -i content-type
curl -s https://lanyards.app/oauth-client-metadata.json
# → JSON whose client_id is https://lanyards.app/oauth-client-metadata.json
curl -sI https://lanyards.app/oauth-client-metadata.json | grep -i content-type
# → application/json
curl -s -o /dev/null -w '%{http_code}\n' https://next.lanyards.app/settings
# → 200
curl -s -o /dev/null -w '%{http_code} %{redirect_url}\n' https://www.lanyards.app/renderg.host
# → 308 https://lanyards.app/renderg.host
for path in / /renderg.host; do
curl -s -o /dev/null -w '%{http_code} %{redirect_url}\n' \
-H 'sec-fetch-dest: document' "https://next.lanyards.app$path"
done
# → 308 https://lanyards.app/ and 308 https://lanyards.app/renderg.host
```

Then sign in with a real account, check your name and handle on `/settings`,
Expand All @@ -185,5 +199,5 @@ sign out, and install the app on a phone and open it offline.

Preview builds work, but Vercel protects previews with Vercel Authentication
by default. Bluesky's servers can't fetch a protected preview's OAuth
metadata, so **sign-in only works on `next.lanyards.app`** (or locally)
unless you relax deployment protection for previews.
metadata, so **sign-in only works on `lanyards.app`** (or locally) unless
you relax deployment protection for previews.
11 changes: 11 additions & 0 deletions web/scripts/vercelConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ describe('vercel.json', () => {
// subdomain's pages move to lanyards.app (#154); only page visits, so
// an installed copy's service worker can still fetch its update there.
it('sends next.lanyards.app pages to lanyards.app, and /@handle to /handle', () => {
const beta = [
{ type: 'host', value: 'next.lanyards.app' },
{ type: 'header', key: 'sec-fetch-dest', value: 'document' },
];
expect(config.redirects).toEqual([
// Vercel's /:path* doesn't match the bare root, so it has its own.
{
source: '/',
has: beta,
destination: 'https://lanyards.app/',
permanent: true,
},
{
source: '/:path*',
has: [
Expand Down
4 changes: 2 additions & 2 deletions web/src/lib/origin/movedOrigin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ describe('movedTo (#154)', () => {

it('leaves every other origin alone: previews, local, Vercel URLs', () => {
for (const href of [
'https://lanyards-next-git-x-renderghost.vercel.app/',
'https://lanyards-next.vercel.app/',
'https://lanyards-git-x-renderghost.vercel.app/',
'https://lanyards-three.vercel.app/',
'http://127.0.0.1:5173/',
]) {
expect(movedTo(href, HOME)).toBeNull();
Expand Down
9 changes: 9 additions & 0 deletions web/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
}
},
"redirects": [
{
"source": "/",
"has": [
{ "type": "host", "value": "next.lanyards.app" },
{ "type": "header", "key": "sec-fetch-dest", "value": "document" }
],
"destination": "https://lanyards.app/",
"permanent": true
},
{
"source": "/:path*",
"has": [
Expand Down
Loading