docker - 在 docker-compose 中结合 Next.JS 和 json-server
问题描述
我正在尝试创建一个 docker-compose 来启动带有json-server后端的 Next.js 应用程序的演示。
当我从一个页面移动到另一个页面时,什么都没有移动(使用 nextjs 链接),直到我从后端获得超时,而后端的日志中没有显示任何请求。之后,如果我重新加载页面,它会立即呈现,并且请求会显示在后端的日志中。此外,客户端请求根本不起作用。
直接访问 fakeapi (http://localhost:3521/) 确实没有问题。
Docker 撰写日志
app_1 | event - build page: /
app_1 | wait - compiling...
app_1 | event - compiled successfully
app_1 | event - build page: /next/dist/pages/_error
>>>> PAGE RELOAD
app_1 | wait - compiling...
app_1 | event - compiled successfully
fakeapi_1 | GET /products?_page=1&_limit=50 200 10.187 ms - 83189
码头工人-compose.yml
version: "3"
services:
app:
image: client/app
depends_on:
- fakeapi
ports:
- "3000:3000"
environment:
- NEXT_PUBLIC_INTERNAL_API_URI=http://fakeapi:3521
networks:
- mynetwork
fakeapi:
image: server/fakeapi
restart: always
ports:
- "3521:3521"
hostname:
fakeapi
networks:
- mynetwork
networks:
mynetwork:
json-server package.json
{
"name": "fake-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "json-server --watch db.json --port 3521 --host 0.0.0.0"
},
"author": "",
"license": "ISC",
"dependencies": {
"json-server": "^0.16.3"
}
}
编辑:尝试为生产构建:页面不再“卡住”,但在我重新加载之前出现“发生意外错误”。客户端请求仍然无法正常工作。
解决方案
推荐阅读
- python - PYTHON-DOTENV:从 vscode fun 按钮运行时不起作用
- reactjs - Api Platform Admin 使用猜测器组件,但不使用 React-admin 经典组件
- sql - 在 SQL 中链接两个表
- tensorflow - MobileNetV2 在 TF 2.2 上的预处理不一致
- java - 带有 Nginx 和预签名 URL 的 Minio
- json - 如何在 Highmaps 中使用自定义 JSON 地图
- javascript - 如何输入图像并将其用作光标?
- css - 媒体查询问题技术评估
- excel - 将重复性任务分成不同的步骤和程序
- c# - 检查文件是否存在并更新表列