【发布时间】:2020-09-12 08:58:43
【问题描述】:
每次在我的应用程序中首次加载页面时,它都会对以下 URL 进行 API 调用:auth/verify。该调用工作正常客户端,但返回一个404错误服务器端(即当用户重新加载页面时)。一种似乎可行的替代方法是更改 url 配置,如下所示
url: process.browser ? 'auth/verify' : 'http://localhost:3000/auth/verify'
这在开发过程中运行良好,但在生产中导致服务器错误。下面是我的代码:
this.$axios({
method: 'post',
url: 'auth/verify',
data: {
token: authToken
}
}).then((response) => {
console.log(response.data)
}).catch(err => {
console.log(err.response.data)
})
解决此问题的最佳方法是什么?
注意:我在 Linux 服务器上托管我的节点应用程序。以下是我的 nuxt.config.js 文件中的一些配置:
router: {
middleware: "auth" /* The middleware making the api call */
},
mode: "universal",
axios: {
baseURL: "/",
proxy: true
},
server: {
host: "0.0.0.0",
port: 3000
}
【问题讨论】:
标签: vue.js axios nuxt.js server-side-rendering