【问题标题】:Supabase Edge function says no body was passedSupabase Edge 函数表示没有传递正文
【发布时间】:2022-12-18 03:23:28
【问题描述】:

我正在使用以下调用 supabase 边缘函数

    async function getData(plan_data){
        console.log(plan_data)
        console.log(JSON.stringify({plan_data}))
        const { data, error } = await supabase.functions.invoke("create-stripe-checkout",
        {
            body: JSON.stringify({
                plan_data
            }),
        }
        )
        console.log(data, error)
        // console.log(data)

    }

在边缘函数中,我控制台记录了请求,它声明 bodyUsed: false。本质上,边缘函数的行为就像并相信没有传递任何值。 (一个值被正确地传递给 getData 函数)。我尝试了一些语法但无济于事,我错过了什么吗?

编辑: 边函数如下

import { serve } from "https://deno.land/std@0.131.0/http/server.ts"

serve(async (req) => {
  if (req.method === "OPTIONS"){
    return new Response (null, {
      headers: {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Headers": "apikey, X-Client-Info, Authorization, content-type", 
      }
    })
  }
  console.log(req)
  const { planId } = await req.json()
  console.log(planId)
  return new Response(
    JSON.stringify({ planId }),
    { headers: { 
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "apikey, X-Client-Info, Authorization, content-type", 
      // "Content-Type": "application/json",
    } },
  )
})

【问题讨论】:

  • 您还可以在 Edge Function 上分享您的代码吗?
  • @dshukertjr 添加了它
  • 感谢您添加它。我假设 console.log(planId) 只是在这里记录 null?您能否分享边缘功能日志中的一些屏幕截图?理想情况下包含bodyUsed: false
  • @dshukertjr 是您要找的图片吗?

标签: javascript typescript supabase


【解决方案1】:

添加内容类型标头是否有效?

async function getData(plan_data) {
  console.log(plan_data)
  console.log(JSON.stringify({ plan_data }))
  const { data, error } = await supabase.functions.invoke("create-stripe-checkout",
  {
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      plan_data
    }),
  });
  console.log(data, error)
}

【讨论】:

  • 不幸的是没有
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-02
  • 2016-09-30
  • 1970-01-01
  • 2021-04-13
相关资源
最近更新 更多