NuxtN
Nuxt3y ago
less

useFetch is not defined in server/api

I want to hit the Api using post method in server/api, but whenever i hit it, it return error 500 server error with message "useFetch is not defined"


import { Buffer } from "buffer";

export default defineEventHandler(async (event) => {
  const config = useRuntimeConfig();
  const body = await readBody(event);
  const { data } = await useFetch(`${config.public.midtransEndpoint}`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Accept: "application/json",
      Authorization:
        "Basic " +
        Buffer.from(`${config.public.midtransServerKey}`).toString("base64"),
    },
    body: {
      body,
    },
  });

  return {
    data,
  };
});
Screenshot_2023-05-03_at_18.47.59.png
Was this page helpful?