angular-cli-webpack
angular-cli-webpack copied to clipboard
overriding/extending devServer properties doesnt work
I am trying to enhance the default CLI configuration of webpack-dev-server. I need to set the following properties:
- devServer
- historyApiFallback: true
- headers
- "Access-Control-Allow-Origin": "http://localhost.devnet"
- "Access-Control-Allow-Credentials": "true"
What I am seeing is. that ngw successfully injects this but it seems that @angular/cli overrides it afterwards... It never gets recognized by webpack-dev-server, whatever property I am setting inside "devServer"
@christianscharr you need usage proxy.conf.js for Angular
ng serve --proxy-config proxy.conf.js
const PROXY_CONFIG = {
"/api/proxy": {
"target": "http://localhost:3000",
"secure": false,
"bypass": function (req, res, proxyOptions) {
req.headers["X-Custom-Header"] = "yes";
}
}
}
module.exports = PROXY_CONFIG;
for historyApiFallback you can usage workaround
- ng build --watch
- run your node server in dist directory (with your history fallback)