Help with proxy config in NUXT 3

Hello everyone i had an issue with the configuration of a nuxt proxy to use with axios. the problem, i think is on Nitro devProxy object. here is the code and console message: nuxt.config.ts: https://pastebin.com/jHJrSq3u Axios config File: https://pastebin.com/HhcqzmP2 if you see in the image, the proxy isnt setted on url, backwards the request get is still on localhost. i hope you can help me, please :C thank you for read.
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
// services/request.tsimport axios from 'axios';// Crear una instan...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
No description
6 Replies
manniL
manniL9mo ago
Alexander Lichter
YouTube
The BEST way to proxy your API in Nuxt
➡️ Proxying routes to your back-end or third party APIs is a common practice! Over the last two years, various strategies came up in Nuxt. But not all of them work equally will. To figure out which two strategies are the recommended ones, we have a look at the four most common strategies, their shortcomings and which ones I would recommend to us...
charles1410
charles1410OP9mo ago
i tried, but the axios config doesnt change the url of proxy, only set the localhost and concatenate the prefix of proxy: localhost:3000/example, where example is the prefix. i dont understand why or where is the issue or bad config.
manniL
manniL9mo ago
lol wait first: devProxy is not the right choice and second: Where did you fgind that nuxt config example? 😄
charles1410
charles1410OP9mo ago
thank you for respond master! i finally solve the issue here is the final solution: on nuxt.config.ts: nitro: { devProxy: { "/api/": "http://192.168.30.244:3000", // Proxy for API routes "/auth/": "http://192.168.30.244:3000", // Proxy for authentication routes }, }, on axios.ts config: const apiClient = axios.create({ baseURL: '/api/', // URL Api headers: { 'Content-Type': 'application/json', }, withCredentials: true, });
manniL
manniL9mo ago
@charles1410 please do not use the dev proxy here as I shown before. it will not be used during SSR
charles1410
charles1410OP9mo ago
thanks a lot, i watched the video and i followed the best way to set a proxy with runtimeconfig. thanks a lot for your help my friend! its all works!!
Want results from more Discord servers?
Add your server