我有一个在 docker 容器中运行的 nuxtjs 应用程序,我正在尝试使用 nuxt 应用程序上的本地主机连接到端点,但不幸的是我得到以下信息
错误 RROR 请求到 http://0.0.0.0/api/articles 失败,原因:连接 ECONNREFUSED 0.0.0.0:80
我正在尝试在 nuxt 配置中进行抓取,以从 getcockpit cms 生成站点地图。
这是抓取的片段。
sitemap: {
hostname: `${process.env.BASE_URL}`,
gzip: true,
routes: async () => {
const articles = await fetch(`http://0.0.0.0/api/articles`, {
method: 'post',
body: JSON.stringify({
filter: {
Published: true
}
})
})
.then((res) => res.json())
.then((values) => {
const results = values.entries
return results
.filter((result) => result.url.length > 0)
.map((result) => result.url)
})
.catch((err) => console.error(err))
return articles
}
},
以及 Docker 文件的副本
FROM node:12.16.1-alpine
# create destination directory
RUN mkdir -p /usr/src/nuxt-app
WORKDIR /usr/src/nuxt-app
# update and install dependency
RUN apk update && apk upgrade
RUN apk add git
# copy the app, note .dockerignore
COPY . /usr/src/nuxt-app/
RUN npm ci
# build necessary, even if no static files are needed,
# since it builds the server as well
RUN npm run build
# expose 5000 on container
EXPOSE 5000
RUN npm config set https-proxy 127.0.0.1:9000
# set app serving to permissive / assigned
ENV NUXT_HOST=0.0.0.0
# set app port
ENV NUXT_PORT=5000
ENV HOST 0.0.0.0
ENV PORT 5000
ENV HTTP_PROXY http://docker.for.mac.localhost.internal:3128
ENV HTTPS_PROXY https://docker.for.mac.localhost.internal:3128
ENV FTP_PROXY ftp://docker.for.mac.localhost.internal:3128
ENV NO_PROXY http://docker.for.mac.localhost.internal:3128
ENV BASE_URL=http://nuxt
ENV GET_ARTICLES_API_TOKEN=token
ENV GET_ARTICLES_URL=example.com
# start the app
CMD [ "npm", "start"]
当前的 Docker Compose
version: "2"
services:
nuxt:
build: .
ports:
- 5000:5000
environment:
ENV NUXT_HOST: 0.0.0.0
ENV NUXT_PORT: 5000
最佳答案
你试过在你的浏览器上访问 localhost:5000
吗?
关于Docker 原因 : connect ECONNREFUSED 0. 0.0.0:80,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60879099/