[英]Nuxt Can't access server on asyncData with docker-compose
I've created this boilerplate https://github.com/sebalaini/laravel_docker-compose that I'm using on another project and I'm unable to fetch data with asyncData
it returns我创建了这个样板https://github.com/sebalaini/laravel_docker-compose我在另一个项目中使用它,我无法使用它返回的
asyncData
获取数据
Error: connect ECONNREFUSED 127.0.0.1:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 80,
...
My code looks like this:我的代码如下所示:
async asyncData ({ $axios, store, req }) {
const userEmail = 'mail@mail.com'
await $axios
.post(`${process.env.BASE_API_URL}/profilepage`, {
email: userEmail
})
.then((resp) => {
store.commit('setUser', resp.data.user)
})
.catch((error) => {
console.log(error)
})
},
the BASE_API_URL
it's BASE_API_URL=http://localhost/api
I've tried also with http://webserver:80/api/profilepage
but no luck. BASE_API_URL
它是BASE_API_URL=http://localhost/api
我也试过http://webserver:80/api/profilepage
但没有运气。
How can I fix it and be able to fecth data also on the server side?我怎样才能修复它并能够在服务器端感染数据? As you can see I have a redirect on the webserver service that points to the Laravel container if match
api|storage
https://github.com/sebalaini/laravel_docker-compose/blob/master/LOCAL/nginx/nginx.conf#L126如您所见,如果匹配
api|storage
https://github.com/sebalaini/laravel_docker-compose/blob/master/LOCAL/nginx/nginx.conf#L126 ,我在网络服务器服务上有一个重定向,该重定向指向 Laravel 容器
I solved the problem even though TBH I don't get the logic.即使TBH我不明白逻辑,我也解决了这个问题。 in the
docker-compose.yml
I have changed port 80:81
in 80:80
and the nginx.conf
to use 80 instead of 81 and now I can use http://webserver/api/... and access the endpoint when on the server side.在
docker-compose.yml
我在80:80
和nginx.conf
中更改了端口80:81
使用 80 而不是 81 现在我可以使用 Z80791B3AE7002ACB88C2468/76D9FA 上的端点访问端点 when://theweb8/76D9FA服务器端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.