-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CORS browser support for search edge function
Temporary solution for now; we should use a fat function in the future
- Loading branch information
1 parent
93b094c
commit 0b2d5c6
Showing
4 changed files
with
16 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { corsHeaders } from "./cors.ts"; | ||
|
||
export function buildResponse(data: object, status: number = 200) { | ||
const dataStr = JSON.stringify(data); | ||
console.info(`Response ${status}: ${dataStr}`); | ||
return new Response(dataStr, { | ||
headers: { "Content-Type": "application/json" }, | ||
headers: { ...corsHeaders, "Content-Type": "application/json" }, | ||
status, | ||
}); | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const corsHeaders = { | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": | ||
"authorization, x-client-info, apikey, content-type", | ||
}; |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import "https://esm.sh/@supabase/functions-js/src/edge-runtime.d.ts"; | |
import { createSupabase } from "../lib/utils/create-supabase.ts"; | ||
import { SupabaseClient } from "https://esm.sh/v135/@supabase/[email protected]/dist/module/index.d.ts"; | ||
import { buildResponse } from "../lib/utils/build-response.ts"; | ||
import { corsHeaders } from "../lib/utils/cors.ts"; | ||
|
||
type ClientFriendlyData = { | ||
href: string; | ||
|
@@ -58,6 +59,10 @@ async function getBillSearchResults( | |
} | ||
|
||
Deno.serve(async (req) => { | ||
if (req.method === "OPTIONS") { | ||
return new Response("ok", { headers: corsHeaders }); | ||
} | ||
|
||
const supabase = createSupabase(); | ||
|
||
const { query } = await req.json(); | ||
|