netlify-redirects.mjs
31 lines 1.7 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 11 days ago
1 /**
2 * Writes public/_redirects so traffic goes to gateway or bridge function.
3 * Gateway site: leave USE_BRIDGE_FUNCTION unset. Bridge site: true (set in Netlify UI
4 * or in deploy/bridge/netlify.toml [build.environment]). Root netlify.toml must not
5 * declare a catch-all [[redirects]]—it would apply to every linked site in the monorepo.
6 */
7 import { mkdir, writeFile, readFile } from 'fs/promises';
8 import { dirname } from 'path';
9 import { fileURLToPath } from 'url';
10
11 const __dirname = dirname(fileURLToPath(import.meta.url));
12 // Base must end with / so `_redirects` is under public/ (otherwise URL resolution drops `public`).
13 const publicDir = new URL('../public/', import.meta.url);
14 const redirectsPath = new URL('_redirects', publicDir);
15
16 const useBridge = process.env.USE_BRIDGE_FUNCTION === 'true' || process.env.USE_BRIDGE_FUNCTION === '1';
17 console.log('[netlify-redirects] USE_BRIDGE_FUNCTION=%s → %s', process.env.USE_BRIDGE_FUNCTION ?? '(unset)', useBridge ? 'bridge' : 'gateway');
18
19 await mkdir(publicDir, { recursive: true });
20 // Both sites must use :splat so the function URL includes the visitor path (e.g. /api/v1/notes).
21 // Without :splat, every request hits the function as "/" and the canister returns 404 Not found.
22 const line = useBridge
23 ? '/* /.netlify/functions/bridge/:splat 200'
24 : '/* /.netlify/functions/gateway/:splat 200';
25 await writeFile(redirectsPath, line + '\n', 'utf8');
26 const content = await readFile(redirectsPath, 'utf8');
27 if (!content.includes(line.trim())) {
28 console.error('[netlify-redirects] Build assertion failed: public/_redirects does not contain expected line:', line.trim());
29 process.exit(1);
30 }
31 console.log('[netlify-redirects] Wrote public/_redirects: %s', line);
File History 4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 11 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 31 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 51 days ago