Last active
October 10, 2023 22:17
-
-
Save ntotten/a61c0f11b07428370d163ec18123f0e3 to your computer and use it in GitHub Desktop.
Revisions
-
ntotten revised this gist
Oct 10, 2023 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,13 @@ export default async function ( newRequest.headers.set('authorization', `Bearer ${environment.SUPABASE_PROD_KEY}`); context.custom.forwardUrl = environment.SUPABASE_PRODUCTION; return newRequest; } else if (url.pathname.startsWith("/api")) { // This assumes that the 'default' environment is production so use the productio info const newRequest = new Request(url.pathname.replace('/v1/', '/'), request); newRequest.headers.set('authorization', `Bearer ${environment.SUPABASE_PROD_KEY}`); context.custom.forwardUrl = environment.SUPABASE_PRODUCTION; return newRequest; } return new Response(JSON.stringify({ message: 'Inexistent environment, please use a valid base URL.' -
ntotten revised this gist
Oct 10, 2023 . 1 changed file with 30 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ import { ZuploContext, ZuploRequest } from "@zuplo/runtime"; export default async function ( request: ZuploRequest, context: ZuploContext, options: any, policyName: string ) { const url = new URL(request.url); if (url.pathname.startsWith('/sandbox')) { const newRequest = new Request(url.pathname.replace('/sandbox/', '/'), request); newRequest.headers.set('authorization', `Bearer ${environment.SUPABASE_STG_KEY}`); context.custom.forwardUrl = environment.SUPABASE_STAGING; return newRequest; } else if (url.pathname.startsWith('/v1')) { const newRequest = new Request(url.pathname.replace('/v1/', '/'), request); newRequest.headers.set('authorization', `Bearer ${environment.SUPABASE_PROD_KEY}`); context.custom.forwardUrl = environment.SUPABASE_PRODUCTION; return newRequest; } return new Response(JSON.stringify({ message: 'Inexistent environment, please use a valid base URL.' }), { status: 404, statusText: 'PXT-AUTH000' }) } -
ntotten created this gist
Oct 10, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ import { ZuploContext, ZuploRequest } from "@zuplo/runtime"; export default async function ( request: ZuploRequest, context: ZuploContext, options: any, policyName: string ) { context.custom.forwardUrl = getForwardUrl(request); return request; } function getForwardUrl(request: ZuploRequest) { // Logic to determine forwarded url here: return "https://my-environment.supabase.com" }