Skip to content

Commit c92a09a

Browse files
Corrigiu runtime do worker
X-Lovable-Edit-ID: edt-043fe084-45af-4514-ac30-34beec56ff56 Co-authored-by: criptogus <128640021+criptogus@users.noreply.github.com>
2 parents c30dd32 + 50afa37 commit c92a09a

5 files changed

Lines changed: 314 additions & 4 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file is automatically generated. Do not edit it directly.
2+
import { createMiddleware } from '@tanstack/react-start'
3+
import { supabase } from './client'
4+
5+
// Must be registered as a global `functionMiddleware` in `src/start.ts`; otherwise
6+
// the browser never attaches the bearer token to serverFn RPCs.
7+
export const attachSupabaseAuth = createMiddleware({ type: 'function' }).client(
8+
async ({ next }) => {
9+
const { data } = await supabase.auth.getSession()
10+
const token = data.session?.access_token
11+
return next({
12+
headers: token ? { Authorization: `Bearer ${token}` } : {},
13+
})
14+
},
15+
)

src/lib/integrations/registry.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,22 @@ export interface Integration {
3838
authors: string[];
3939
}
4040

41-
const DEFAULT_DIR = new URL("../../../content/integrations/", import.meta.url).pathname;
41+
// Lazily resolve the content dir. `new URL(..., import.meta.url)` throws
42+
// "Invalid URL string." inside the bundled Cloudflare Worker because
43+
// import.meta.url is not a usable base there. Resolving it eagerly at module
44+
// init would crash SSR for every request that imports this file.
45+
function resolveDefaultDir(): string {
46+
try {
47+
return new URL("../../../content/integrations/", import.meta.url).pathname;
48+
} catch {
49+
return "";
50+
}
51+
}
4252

4353
let cache: Map<string, Integration> | null = null;
4454

45-
export function loadIntegrations(dir = DEFAULT_DIR): Map<string, Integration> {
55+
export function loadIntegrations(dir?: string): Map<string, Integration> {
56+
dir = dir ?? resolveDefaultDir();
4657
if (cache) return cache;
4758
const out = new Map<string, Integration>();
4859
let entries: string[] = [];

0 commit comments

Comments
 (0)