fix: use custom fetch wrapper in supabase ssr to route traffic internally and avoid fetch failed edge errors
This commit is contained in:
@@ -28,6 +28,22 @@ export async function middleware(req: NextRequest) {
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
{
|
||||
global: {
|
||||
fetch: (url, options) => {
|
||||
const u = new URL(url.toString());
|
||||
if (process.env.NODE_ENV === 'production' && u.hostname === 'supabase.4ventures.es') {
|
||||
u.protocol = 'http:';
|
||||
u.hostname = 'ventures-web-supabase-gm0nnn-supabase-kong';
|
||||
u.port = '8000';
|
||||
if (!options) options = {};
|
||||
if (!options.headers) options.headers = new Headers();
|
||||
const headers = new Headers(options.headers);
|
||||
headers.set('Host', 'supabase.4ventures.es');
|
||||
options.headers = headers;
|
||||
}
|
||||
return fetch(u.toString(), options);
|
||||
}
|
||||
},
|
||||
cookies: {
|
||||
getAll() {
|
||||
return req.cookies.getAll();
|
||||
|
||||
Reference in New Issue
Block a user