node.js - Express 服务器作为 Docker 镜像容器运行,只为一些 html 页面提供服务
问题描述
问题
Node/express Docker 映像在本地运行,服务于一些 html 页面而不是其他页面
解释
我有一个 Node/Express 应用程序作为 Docker 映像,作为 Docker 容器在本地运行。这是一个应用程序在使用 Express 时以通常的方式提供 html 页面。但是,尽管快速路线几乎相同,但似乎我只能访问其中一些页面,而不能访问其他页面
server.js
app.get('/', function (req, res) {
res.render('index', {
user: req.user
});
});
app.get('/signup/terms', function (req, res, ) {
res.render('signup/terms', {
user: req.user
})
})
app.get('/signup/map', function (req, res, ) {
res.render('signup/map', {
user: req.user
})
})
我可以访问 index 和 /signup/terms 没问题,加载所有 html、css 和图像,但是当我访问 /signup/map 时,我得到一个 500 状态码
GET /signup/map 500 5.980 ms - 47
我尝试过的事情:
我尝试使用以下命令查看 docker 容器文件目录:
docker exec -it <container> sh
检查所有文件是否存在,并且图像是最新的。
这是我用来构建图像的 docker 配置:
FROM node:10-alpine
# Create app directory
WORKDIR /app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
# DEV RUN npm install
# If you are building your code for production
# RUN npm ci --only=production
RUN npm ci --only=production
# Bundle app source
COPY . /app
EXPOSE 3000
CMD [ "node", "server.js" ]
我也尝试使用 --no-cache 选项重建图像,但无济于事。
我认为这可能是一个目录问题,但有些页面正在服务而有些没有这一事实令人困惑......
有谁知道这里发生了什么?
更新:原来这是 ejs 模板的问题。我的页面有未传递的变量,导致服务器抛出 500 状态。
解决方案
推荐阅读
- elasticsearch - 在 elasticsearch 中对文本和关键字运行范围查询
- batch-file - 在 ffmpeg 中收到错误“为“缩放”过滤器指定的输入过多”
- containers - 虚拟机与容器
- c# - 如何使用 Bitmap 和 WPF 实现 Minimap / Mapcontrol
- kubernetes - 如何获取 Prometheus 中每个 worker_group 的节点号?
- java - Switch-Case 内的 For 循环 - Java
- node.js - this._handle 在 Node 8 的 net.js 中变为 null
- python - 获取 AttributeError:模块 'base64' 在 python 3.9.6 上运行时没有属性 'decodestring' 错误
- php - varchar 格式的日期不适用于带有日期的查询
- drbd - DeviceioControl() 失败,错误为 1 // 使用 WinDRBD