我正在向 express url“getstatus”发送 axios 请求 - 在我的本地开发中一切正常,但是一旦文件在服务器上,url 路径中仍然有我的本地主机。
this.$axios.get('api/getstatus', {
}).then(function (response) {
})
.catch(function (error) {
});
app.get('/getstatus', async (req, res) => {
// stuff happening
})
-> 在本地主机上正常 -> 服务器错误:请求 URL:http://localhost:3000/api/getstatus
为什么我的本地开发 url 仍然被使用?应该是http://myserver.com/api/getstatus
最佳答案
看来 axios get 请求应该是 /api/getstatus
而不是 api/getstatus
另一件事是你应该在你的点环境文件中设置一个 API_URL 变量,在开发中将它设置为本地主机,在你的服务器上将它设置为你的服务器 URL。
像这样
this.$axios.get(`${process.env.API_URL}/api/getstatus`, {
}).then(function (response) {
// Code here
})
catch(function (error) {
// Error code here
});
关于javascript - express get url 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54675665/