1
votes

Can't seem to find this anywhere...

Is it possible for Axios calls within Nuxt to be called with automatic relative paths?

To state the case more specifically, I'd like to be able to not have to set a server-side API (express serverMiddleware) base URL specifically, but make it update for:

  1. localhost:3000
  2. myliveurl.com
  3. generated-netlify-url-with-93394932-numbers.netlify.com (the kicker here -- for deploy previews.)

Would appreciate any help.

Thanks!

1

1 Answers

1
votes

Just add this to your nuxt.config.js

axios: {
    baseURL: '/api/',
},

and this will use relative directory api/:

  1. localhost:3000/api/...
  2. myliveurl.com/api/...
  3. generated-netlify-url-with-93394932-numbers.netlify.com/api/...