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
4 changes: 2 additions & 2 deletions 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` 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`; `www` redirects to it. Production's address is fixed in code (`PRODUCTION_BASE_URL`, #159)

**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 All @@ -92,7 +92,7 @@ AT Protocol OAuth will reject `localhost` with "invalid_request" error.

**OAuth Client Configuration (`web/`):**
- **Local development and e2e** (`http://127.0.0.1:5173` / `:4173`): uses the RFC 8252 loopback client. Its `client_id` is literally `http://localhost?redirect_uri=…&scope=…`; that's the only place `localhost` appears, and every redirect URI uses `127.0.0.1`.
- **Production and preview** (`https://`): the client metadata is generated at build time into `oauth-client-metadata.json` from `PUBLIC_BASE_URL` (or Vercel's branch URL for previews), by `web/plugins/oauthMetadata.ts`.
- **Production and preview** (`https://`): the client metadata is generated at build time into `oauth-client-metadata.json` by `web/plugins/oauthMetadata.ts`, for `https://lanyards.app` in Vercel production (`PRODUCTION_BASE_URL`), Vercel's branch URL for previews, and `PUBLIC_BASE_URL` for other builds.
- Access the dev app via `http://127.0.0.1:5173` (NOT localhost)

---
Expand Down
30 changes: 10 additions & 20 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,22 @@ Environment Variables"** on, because preview builds use `VERCEL_ENV` and

| 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. Don't set it for Preview:
previews use their own branch URL.
The OAuth client metadata and canonical links are built from the app's
address. Vercel production is always `https://lanyards.app`, fixed in code
(`PRODUCTION_BASE_URL` in `src/lib/atproto/oauthConfig.ts`), so no variable
can put another origin in the OAuth client (#159). Previews use their own
branch URL. `PUBLIC_BASE_URL` sets the address for other builds, such as
`npm run build:e2e`; Vercel doesn't need it.

### 3. Domains

| 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 |

`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.
| Domain | Setting |
| ------------------ | ------------------------------- |
| `lanyards.app` | Production, primary |
| `www.lanyards.app` | Redirect to `lanyards.app`, 308 |

DNS is on Cloudflare. Keep every Vercel record **DNS only** (grey cloud) so
Vercel can issue certificates. The `_atproto` TXT record verifies the
Expand All @@ -184,11 +179,6 @@ curl -sI https://lanyards.app/oauth-client-metadata.json | grep -i content-type
# → application/json
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 Down
3 changes: 2 additions & 1 deletion web/api/meta.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFile } from 'node:fs/promises';

import { createMetaHandler } from '../server/metaHandler.ts';
import { runtimeBaseUrl } from '../src/lib/atproto/oauthConfig.ts';

let index: Promise<string> | undefined;

Expand All @@ -16,5 +17,5 @@ function readIndex(): Promise<string> {
/** /:handle and /d/:did, with person-specific link-preview meta. */
export const GET = createMetaHandler({
readIndex,
baseUrl: process.env.PUBLIC_BASE_URL,
baseUrl: runtimeBaseUrl(process.env),
});
27 changes: 3 additions & 24 deletions web/scripts/vercelConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,10 @@ const config = JSON.parse(
) as Config;

describe('vercel.json', () => {
// The beta's /@handle links, link previews included (#150). The beta
// 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' },
];
// The beta's /@handle links, link previews included (#150). Nothing
// else redirects: next.lanyards.app is gone (#159).
it('sends /@handle on to /handle for good, and nothing else', () => {
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: [
{ type: 'host', value: 'next.lanyards.app' },
{ type: 'header', key: 'sec-fetch-dest', value: 'document' },
],
destination: 'https://lanyards.app/:path*',
permanent: true,
},
{ source: '/@:handle', destination: '/:handle', permanent: true },
]);
});
Expand Down
6 changes: 3 additions & 3 deletions web/server/html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ describe('injectMeta', () => {

describe('defaultMeta', () => {
it('describes Lanyards itself, with the default image', () => {
expect(defaultMeta('https://next.lanyards.app')).toEqual({
expect(defaultMeta('https://lanyards.app')).toEqual({
title: 'Lanyards',
description: 'Your conference lanyard on the AT Protocol',
canonical: 'https://next.lanyards.app/',
image: 'https://next.lanyards.app/og/default.png',
canonical: 'https://lanyards.app/',
image: 'https://lanyards.app/og/default.png',
imageAlt: 'Lanyards',
type: 'website',
});
Expand Down
22 changes: 11 additions & 11 deletions web/server/metaHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ const handler = (fetchImpl: typeof fetch = profileFetch) =>
createMetaHandler({
readIndex: async () => INDEX,
fetchImpl,
baseUrl: 'https://next.lanyards.app',
baseUrl: 'https://lanyards.app',
});

describe('meta handler', () => {
it('serves the app with person-specific meta, cached for ten minutes', async () => {
const response = await handler()(
new Request('https://next.lanyards.app/alice.test?handle=alice.test')
new Request('https://lanyards.app/alice.test?handle=alice.test')
);
const html = await response.text();
expect(response.status).toBe(200);
Expand All @@ -42,14 +42,14 @@ describe('meta handler', () => {
'<meta property="og:title" content="Ada Example (@alice.test) · Lanyards" />'
);
expect(html).toContain(
`<meta property="og:image" content="https://next.lanyards.app/og/p/${DID}.png" />`
`<meta property="og:image" content="https://lanyards.app/og/p/${DID}.png" />`
);
});

it('reads the handle or DID from the path when the query has none', async () => {
const fetchImpl = vi.fn(profileFetch);
await handler(fetchImpl as unknown as typeof fetch)(
new Request(`https://next.lanyards.app/d/${DID}`)
new Request(`https://lanyards.app/d/${DID}`)
);
expect(String(vi.mocked(fetchImpl).mock.calls[0]?.[0])).toContain(
`actor=${encodeURIComponent(DID)}`
Expand All @@ -59,7 +59,7 @@ describe('meta handler', () => {
it('reads a bare handle from the path, the lanyard’s address (#150)', async () => {
const fetchImpl = vi.fn(profileFetch);
await handler(fetchImpl as unknown as typeof fetch)(
new Request('https://next.lanyards.app/alice.test')
new Request('https://lanyards.app/alice.test')
);
expect(String(vi.mocked(fetchImpl).mock.calls[0]?.[0])).toContain(
'actor=alice.test'
Expand All @@ -73,19 +73,19 @@ describe('meta handler', () => {
{ status: 400 }
)) as typeof fetch;
const response = await handler(missing)(
new Request('https://next.lanyards.app/nobody.test?handle=nobody.test')
new Request('https://lanyards.app/nobody.test?handle=nobody.test')
);
expect(response.status).toBe(200);
expect(response.headers.get('cache-control')).toBe('public, s-maxage=60');
expect(await response.text()).toContain(
'<meta property="og:image" content="https://next.lanyards.app/og/default.png" />'
'<meta property="og:image" content="https://lanyards.app/og/default.png" />'
);
});

it.each([
'https://next.lanyards.app/@ada%',
'https://next.lanyards.app/@x?handle=ada%25',
'https://next.lanyards.app/d/did%3Aplc%3Aa%',
'https://lanyards.app/@ada%',
'https://lanyards.app/@x?handle=ada%25',
'https://lanyards.app/d/did%3Aplc%3Aa%',
])('serves default meta for a malformed escape in %s', async (url) => {
const fetchImpl = vi.fn(profileFetch);
const response = await handler(fetchImpl as unknown as typeof fetch)(
Expand All @@ -99,7 +99,7 @@ describe('meta handler', () => {
it('never looks up something that is not a handle or DID', async () => {
const fetchImpl = vi.fn(profileFetch);
const response = await handler(fetchImpl as unknown as typeof fetch)(
new Request('https://next.lanyards.app/@x?handle=%3Cscript%3E')
new Request('https://lanyards.app/@x?handle=%3Cscript%3E')
);
expect(fetchImpl).not.toHaveBeenCalled();
expect(await response.text()).toContain('<title>Lanyards</title>');
Expand Down
16 changes: 8 additions & 8 deletions web/server/ogHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('OG image handler', () => {
'image/jpeg'
);
await createOgHandler({ fetchImpl: impl, render })(
new Request(`https://next.lanyards.app/api/og?did=${DID}`)
new Request(`https://lanyards.app/api/og?did=${DID}`)
);
expect(urls).toContain(
`https://cdn.bsky.app/img/avatar_thumbnail/plain/${DID}/bafkreiavatar@jpeg`
Expand All @@ -75,7 +75,7 @@ describe('OG image handler', () => {
'image/webp'
);
await createOgHandler({ fetchImpl: impl, render })(
new Request(`https://next.lanyards.app/api/og?did=${DID}`)
new Request(`https://lanyards.app/api/og?did=${DID}`)
);
expect(render).toHaveBeenCalledWith(
expect.not.objectContaining({ avatarDataUri: expect.anything() })
Expand All @@ -85,7 +85,7 @@ describe('OG image handler', () => {
it('draws the person’s badge with their small avatar', async () => {
const render = vi.fn(async () => PNG);
const response = await createOgHandler({ fetchImpl, render })(
new Request(`https://next.lanyards.app/og/p/${DID}.png?did=${DID}`)
new Request(`https://lanyards.app/og/p/${DID}.png?did=${DID}`)
);
expect(response.headers.get('content-type')).toBe('image/png');
expect(response.headers.get('cache-control')).toBe(
Expand All @@ -102,15 +102,15 @@ describe('OG image handler', () => {
it('draws the default badge without a DID', async () => {
const render = vi.fn(async () => PNG);
await createOgHandler({ fetchImpl, render })(
new Request('https://next.lanyards.app/og/default.png')
new Request('https://lanyards.app/og/default.png')
);
expect(render).toHaveBeenCalledWith(null);
});

it('keeps the default badge for a day when no person was asked for', async () => {
const render = vi.fn(async () => PNG);
const response = await createOgHandler({ fetchImpl, render })(
new Request('https://next.lanyards.app/og/default.png')
new Request('https://lanyards.app/og/default.png')
);
expect(response.headers.get('cache-control')).toBe(
'public, s-maxage=86400, stale-while-revalidate=604800'
Expand All @@ -122,7 +122,7 @@ describe('OG image handler', () => {
const failing = (async () =>
new Response(null, { status: 500 })) as typeof fetch;
const response = await createOgHandler({ fetchImpl: failing, render })(
new Request(`https://next.lanyards.app/api/og?did=${DID}`)
new Request(`https://lanyards.app/api/og?did=${DID}`)
);
expect(render).toHaveBeenCalledWith(null);
expect(response.headers.get('cache-control')).toBe('public, s-maxage=60');
Expand All @@ -135,7 +135,7 @@ describe('OG image handler', () => {
return PNG;
});
const response = await createOgHandler({ fetchImpl, render })(
new Request(`https://next.lanyards.app/api/og?did=${DID}`)
new Request(`https://lanyards.app/api/og?did=${DID}`)
);
expect(render).toHaveBeenLastCalledWith(null);
expect(response.status).toBe(200);
Expand All @@ -151,7 +151,7 @@ describe('OG image handler', () => {
throw new Error('wasm failed to load');
});
const response = await createOgHandler({ fetchImpl, render })(
new Request(`https://next.lanyards.app/api/og?did=${DID}`)
new Request(`https://lanyards.app/api/og?did=${DID}`)
);
expect(response.status).toBe(503);
expect(response.headers.get('cache-control')).toBe('no-store');
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/QrCode/QrCode.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { renderWithProviders } from '@/test/render';

import { QrCode } from './QrCode';

const URL = 'https://next.lanyards.app/d/did:plc:fixturealiceaaaaaaaaaaaa';
const URL = 'https://lanyards.app/d/did:plc:fixturealiceaaaaaaaaaaaa';

/** Paints the module matrix, with a 4-module quiet zone, and scans it. */
function scan(code: Bitmap2D): string | undefined {
Expand Down
Loading
Loading