Nuxt 3 sending formData using routeRules & useFetch()

200 views Asked by At

I use routeRules to proxy requests to backend:


  routeRules: {
    '/api/**': {
      proxy: process.env.BASE_URL
        ? `${process.env.BASE_URL}/**`
        : 'http://127.0.0.1:5000/api/**',
    }
  },

Request which should be sent to backend:


const { data, pending, error, refresh } = await useServerAPI(
  '/image/upload',
  {
    method: 'POST',
    body: formData,
    credentials: 'include',
  }
)

And i receive error: [nuxt] [request error] [unhandled] [500] fetch failed. If i set body with no formData with file request works as expected (returns Unprocessable entity with NestJS Multer plugin).

useServerAPI.ts composable code:

import { useFetch } from '#app'
type useFetchType = typeof useFetch
export const useServerAPI: useFetchType = (path, options = {}) => {
  const config = useRuntimeConfig()

  options.baseURL = config.public.baseURL as string
  return useFetch(path, options)
}
0

There are 0 answers