Reputation: 21
I am currently trying my hand with Supabase's edge functions. I don't know anything about this area, so I tried the quickstart tutorial first. I created the simple "hello-world" function (from the documentation https://supabase.com/docs/guides/functions/quickstart) and tried to call it from my java script code. I have turned off the JWT verification. But when I call the function I always get "FunctionsFetchError" back. In the dashboard the error looks like this:
Log Event Message
SyntaxError: Unexpected end of JSON input
at parse ()
at packageData (ext:deno_fetch/22_body.js:362:14)
at consumeBody (ext:deno_fetch/22_body.js:239:12)
at async Server. (file:///src/index.ts:7:23)
at async Server.#respond (https://deno.land/[email protected]/http/server.ts:221:24)
If you want to try it yourself: https://gwhzelyucjyglpyptrox.functions.supabase.co/hello-world
I didn't change anything at all in the code of the example function, but still can't get it to work.
Upvotes: 1
Views: 2317
Reputation: 21
I had the same issue. Finally I figured out that is because the request has been consumed during the OPTION check request.
To avoid this error:
serve(async (req) => {
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: { ...corsHeaders }, status: 200 })
}
// send a response to the OPTION request before you use the req object.
const origin = req.headers.get('Origin')
console.log('origin is :', origin)
const { test } = await req.json()
// Now you can consume the req object and do your things.
Upvotes: 2