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截图:
内容的提问来源于stack exchange,提问作者ChanGan
相关产品推荐
相关产品推荐

