Hello, I’ve created my first netlify function inside my Nuxt3 project:
netflify/functions/hello.mts
import type { Context } from "@netlify/functions"
export default async (req: Request, context: Context) => {
return new Response("Hello, world!")
}
I want to call this funcion from inside Nuxt3 server/api/call-function.ts
but I am not sure about which path to use?
Do I need to use https://nuxt3-netlify-functions.netlify.app/.netlify/functions/hello
in my $fetch
request, or something like BASE_URL
to not hardcode it or how can I use something like /.netlify/functions/hello
?
export default defineEventHandler(async (event) => {
// QUESTION - how to call this without the full URL?
// ❌ this does NOT work locally
// const whatever = await $fetch('/.netlify/functions/hello')
// when running `netfliy dev` this will work if I use this full URL
// http://localhost:8888/.netlify/functions/hello
// how is this supposed to work in production? Do I something like BASE_URL?
// this works
const whatever = await $fetch('https://nuxt3-netlify-functions.netlify.app/.netlify/functions/hello')
console.log("🐥🐥", whatever)
return whatever
})
My function is up and running here:
https://nuxt3-netlify-functions.netlify.app/.netlify/functions/hello
My whole repo is here:
Many thanks in advance!