Axios BaseURL在某些主机上不起作用 [英] Axios BaseURL not working on certain hosts

查看:83
本文介绍了Axios BaseURL在某些主机上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我根据在Nuxt.js网站上给出的示例配置Axios的方法.>:

Below is how I configured Axios based on the example given on Nuxt.js' website:

.env:

BASE_URL=https://path.to.endpoint

nuxt.config.js:

nuxt.config.js:

publicRuntimeConfig: {
  axios: {
    baseURL: process.env.BASE_URL
  }
},

在页面加载时,我会拨打电话:

On page load I make this call:

this.$axios.get(`/endpoint`)

一旦我将应用程序部署为静态站点,它就可以在我的个人主机和GitHub页面上运行.但是在我雇主的主机上,在 .env 中指定的端点的路径变为 https://localhost:3000 ,因此API调用失败.

Once I deploy my app as a static site it works both on my personal host and on GitHub pages. But on my employer's host, the path to endpoint specified in .env becomes https://localhost:3000 so the API call fails.

为什么最有可能导致这种行为?

Why is the most likely cause of this behaviour?

推荐答案

好的,从注释中看,您提供的配置似乎完全可以满足您的要求,而另一侧的团队的设置确实不正确的环境变量.

Alright, from the comments, it looks like you configuration is totally fine from what you've provided and that the team on the other side does have an incorrect setup of the environment variables.

您需要询问它们在哪里托管您的代码以及它们的env变量的实际值是多少.实际上,您可能需要将其提供给他们,因为他们(通常)无法自己猜测.

You need to ask where they do host your code and what are the actual values of their env variables. Actually, you will probably need to give it to them since they (usually) cannot guess it by themselves.

下一步是人际交流.^^

Human communication is the next step. ^^

这篇关于Axios BaseURL在某些主机上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆