admin管理员组文章数量:1305386
Let's say I'm developing a platform with multi micro-services, and Nuxt frontend service is one of them. I'm using Axios inside a nuxt middleware (which is running in both server and client). inside the nuxt service, the API baseURL is an internal call in local machine, but from client-side, the baseURL is the public app domain off course.
I can solve it using the server's request object, or config files, or to distinguish the run environment. Every option i mentioned can work, but right now I'm looking for a best practice for different client vs. server environment variables.
the middleware file:
import axios from 'axios'
export default function ({ route }) {
return axios.get('api/some-data');
}
request from server should call to "http://internal-service:SOME_PORT/api/some-data.
request from client should call to ".
Let's say I'm developing a platform with multi micro-services, and Nuxt frontend service is one of them. I'm using Axios inside a nuxt middleware (which is running in both server and client). inside the nuxt service, the API baseURL is an internal call in local machine, but from client-side, the baseURL is the public app domain off course.
I can solve it using the server's request object, or config files, or to distinguish the run environment. Every option i mentioned can work, but right now I'm looking for a best practice for different client vs. server environment variables.
the middleware file:
import axios from 'axios'
export default function ({ route }) {
return axios.get('api/some-data');
}
request from server should call to "http://internal-service:SOME_PORT/api/some-data.
request from client should call to "http://my-domain./api/some-data.
Share Improve this question asked Aug 15, 2019 at 8:05 David Meir-LevyDavid Meir-Levy 2522 silver badges11 bronze badges1 Answer
Reset to default 12I found the answer during writing the question..
inside the nuxt.config.js file:
axios: {
baseURL: 'http://internal-service:5000',
browserBaseURL: 'http://my-domain.' //can use environment variables to fill both..
},
本文标签: javascriptDifferent baseURL for server and client API calls with axios amp nuxtStack Overflow
版权声明:本文标题:javascript - Different baseURL for server and client API calls with axios & nuxt - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741805170a2398457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论