Fonti
Fonti
NNuxt
Created by Fonti on 2/20/2024 in #❓・help
Proxy API doesn't work in vercel
I following this video https://www.youtube.com/watch?v=J4E5uYz5AY8 from @manniL / TheAlexLichter and I have this [...].ts file inside server/api folder
// Proxy all requests to the API to the configured API base URL.
// See https://www.youtube.com/watch?v=J4E5uYz5AY8

import { joinURL } from 'ufo'

export default defineEventHandler(async (event) => {
const proxyUrl = useRuntimeConfig().apiBaseUrl
const path = event.path.replace(/^\/api\//, '')
const target = joinURL(proxyUrl, path)
return proxyRequest(event, target)
})
// Proxy all requests to the API to the configured API base URL.
// See https://www.youtube.com/watch?v=J4E5uYz5AY8

import { joinURL } from 'ufo'

export default defineEventHandler(async (event) => {
const proxyUrl = useRuntimeConfig().apiBaseUrl
const path = event.path.replace(/^\/api\//, '')
const target = joinURL(proxyUrl, path)
return proxyRequest(event, target)
})
The proxy is working on local env and I just figured out when I deploy the apps using Vercel, I got the 404 when I hit the endpoint. I also already set the env variable in Vercel same as my local env
9 replies