Skip to content

Unable to customize webpack dev headers when using proxy.conf.json #5968

@ericis

Description

@ericis

Feature Request

- [ ] bug report -> please search issues before submitting
- [ x ] feature request

Versions.

@angular/cli: 1.0.0
node: 6.9.4
os: win32 x64
@angular/animations: 4.0.1
@angular/common: 4.0.1
@angular/compiler: 4.0.1
@angular/core: 4.0.1
@angular/forms: 4.0.1
@angular/http: 4.0.1
@angular/platform-browser: 4.0.1
@angular/platform-browser-dynamic: 4.0.1
@angular/platform-server: 4.0.1
@angular/router: 4.0.1
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.1

Repro steps.

Attempt to add an extra HTTP header to the webpack dev server that is passed on to proxy requests.

The log given by the failure.

n/a

Desired functionality.

Allow the definition of proxy headers in "proxy.config.json" and add them to proxied requests through the bypass function.

Example:

{
  "/api": {
    "target": "http://localhost:8080",
    "secure": false,
    "headers": { 
      "x-custom-thing": "mySpecialValue"
    },
    "pathRewrite": {"^/api" : ""}
  }
}

Mention any other details that might be useful.

On line 154 of the serve task, we could add something like the following:

if (proxyConfig.headers) {
  webpackDevServerConfiguration.proxy.bypass = (req, res, proxyOptions) => {
    // loop through the headers defined in the proxy config
    // req.headers[proxyHdrKey] = proxyHdrValue;
  };
}

We would also have to remove the proxyConfig.headers value before setting the IWebpackDevServerConfigurationOptions.proxy option (e.g. create a copy of the proxy headers before creating the dev server and call delete proxyConfig.headers;.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions