Files
supabase/apps/www/eslint-rules/no-cross-zone-link.cjs
anthony lio b610d677c5 feat(www): lw16 launch week rewrite (#54315)
## Problem

- supabase.com/launch-week shows the lw15 page, and the lw16 card app
runs as a separate vercel app
- a forward rule for all of `/launch-week/*` also covers the www pages
of past launch weeks, and www does not add its security headers to
forwarded paths

## Solution

- moves the lw15 page to `/launch-week/15`
- adds rewrites that forward `/launch-week` and its other paths to the
lw16 card app at `launch-week-16.vercel.app/launch-week/`
- changes the root rule to target `/launch-week/` directly because www
removes the trailing slash and the app adds it, a loop otherwise
- keeps `/launch-week/7`, `/8`, `/15`, `/ticket` and `/tickets/*` on www
with the www security headers
- adds the launch week paths to the security header tests
- adds `/launch-week` to the paths that the redirect checks leave to
other apps

## Preview links

| Site | Live | Preview | Search for |
| ---- | ---- | ------- | ---------- |
| WWW | [/launch-week](https://supabase.com/launch-week) |
[/launch-week](https://zone-www-dot-com-git-antlio-lw16-launch-week-rewrite-supabase.vercel.app/launch-week)
| Claim your card |
| WWW | [/launch-week/15](https://supabase.com/launch-week/15) |
[/launch-week/15](https://zone-www-dot-com-git-antlio-lw16-launch-week-rewrite-supabase.vercel.app/launch-week/15)
| Launch Week 15 |

## Review instructions

1. run `pnpm --filter www exec vitest run lib/security-headers.test.ts`
and make sure that all tests pass
2. open the preview
[/launch-week](https://zone-www-dot-com-git-antlio-lw16-launch-week-rewrite-supabase.vercel.app/launch-week)
and make sure that the lw16 card page loads with no redirect loop
3. open the preview
[/launch-week/](https://zone-www-dot-com-git-antlio-lw16-launch-week-rewrite-supabase.vercel.app/launch-week/)
and make sure that www redirects it to `/launch-week` once

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-12-01 14:45:55 -06:00

85 lines
2.7 KiB
JavaScript

const { readFileSync } = require('node:fs')
const { join } = require('node:path')
const vm = require('node:vm')
const { getProxiedPathPatterns } = require('../lib/security-headers.js')
const SUPABASE_ORIGIN = 'https://supabase.com'
// Evaluated as production: the /docs rewrite only exists there, and /docs links must be flagged in every environment.
function loadProductionRewrites() {
const rewritesModule = { exports: [] }
const source = readFileSync(join(__dirname, '../lib/rewrites.js'), 'utf8')
vm.runInNewContext(source, {
module: rewritesModule,
process: { env: { NEXT_PUBLIC_VERCEL_ENV: 'production' } },
})
return rewritesModule.exports
}
// next.js path matching, so a regex source flags only the paths that it proxies
const crossZonePatterns = getProxiedPathPatterns(loadProductionRewrites()).map(
(pattern) => new RegExp(`^(?:${pattern})$`, 'i')
)
function parseHref(href) {
try {
return new URL(href, SUPABASE_ORIGIN)
} catch {
return null
}
}
function isCrossZonePath(href) {
const url = parseHref(href)
if (url?.origin !== SUPABASE_ORIGIN) return false
return crossZonePatterns.some((pattern) => pattern.test(url.pathname.slice(1)))
}
function staticHrefPrefix(value) {
if (!value) return null
if (value.type === 'Literal') return typeof value.value === 'string' ? value.value : null
if (value.type !== 'JSXExpressionContainer') return null
const { expression } = value
if (expression.type === 'Literal' && typeof expression.value === 'string') return expression.value
if (expression.type === 'TemplateLiteral') return expression.quasis[0].value.cooked
return null
}
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
messages: {
crossZone:
"'{{href}}' is served by another zone. Use a plain <a>: Next.js can't prefetch or client-navigate across zones, so <Link> 404s its prefetch.",
},
schema: [],
},
create(context) {
const linkNames = new Set()
return {
ImportDeclaration(node) {
if (node.source.value !== 'next/link') return
for (const specifier of node.specifiers) {
if (specifier.type === 'ImportDefaultSpecifier') linkNames.add(specifier.local.name)
}
},
JSXOpeningElement(node) {
if (node.name.type !== 'JSXIdentifier' || !linkNames.has(node.name.name)) return
const hrefAttribute = node.attributes.find(
(attribute) => attribute.type === 'JSXAttribute' && attribute.name.name === 'href'
)
const href = staticHrefPrefix(hrefAttribute?.value)
if (!href || !isCrossZonePath(href)) return
context.report({ node: hrefAttribute, messageId: 'crossZone', data: { href } })
},
}
},
}