You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署Node.js+Angular应用返回失败,寻求问题排查方案

Docker部署Angular+Express+MongoDB Atlas POC项目的CORS问题

我正在搭建一个集成Angular、Express、Node.js和MongoDB Atlas的Docker POC项目:

  • Angular运行在4200端口
  • Node.js(Express)运行在3000端口

项目在本地环境运行完全正常,但部署到Docker后出现异常:

  • Docker容器内的Node.js服务已正常启动,文件列表显示无问题
  • 直接访问http://localhost/user能正常返回数据
  • 但浏览器端发起的请求始终失败

我已经尝试了多种CORS配置(代码如下),也改用本地IPhttp://192.168.0.103/访问,都没能解决问题。

项目代码地址:https://github.com/changan1111/UserManagement

app.use(cors());

/*
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "req.headers.origin"); // update to match the domain you will make the request from
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  res.header("Access-Control-Allow-Methods", "DELETE,PUT,GET,POST");

  next();
});*/


/*
app.use(cors({
  "origin": ['http://localhost:3000'],
  "methods": "GET,PUT,POST",
  "preflightContinue": false,
   "credentials": true
}));*/

Dockerfile截图:
Dockerfile截图


内容的提问来源于stack exchange,提问作者ChanGan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 06:01:04