在AWS上使用代理文件构建Angular-Cli

问题描述 投票:0回答:1

我正在尝试使用代理文件构建Angular Build我可以使用代理文件但代理不使用Angular构建

 [{
    "context": ["/api1", "/api2"],
    "target": "http://api.expamle.com",
    "secure": false,
    "changeOrigin": true
 }]

api应该工作当我使Build我得到CORS错误

proxy angular-cli
1个回答
0
投票

如果您使用AWS Docker镜像来部署代码,则需要将http-proxy-middleware添加到package.json文件中,并将以下代码添加到index.js或运行命令的任何其他文件中。

const proxy = require('http-proxy-middleware')
var apiProxy = proxy('/api', {target: 'http://www.example.org/api'});
app.use(apiProxy)
© www.soinside.com 2019 - 2024. All rights reserved.