angular-cli-webpack icon indicating copy to clipboard operation
angular-cli-webpack copied to clipboard

overriding/extending devServer properties doesnt work

Open christianscharr opened this issue 7 years ago • 1 comments

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 avatar Jun 07 '18 14:06 christianscharr

@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

  1. ng build --watch
  2. run your node server in dist directory (with your history fallback)

splincode avatar Jul 20 '18 16:07 splincode