Skip to content

proxy-config does only rewrite request when not available locally #6408

@toaditoad

Description

@toaditoad

Bug Report or Feature Request (mark with an x)

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

Versions.

ng --version
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / â–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.4
node: 6.10.3
os: win32 x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/compiler-cli: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/upgrade: 2.4.10
@angular/cli: 1.0.4

As also shown in many other issues and SO posts, I try to create a proxy and redirect requests from my frontend (localhost:4200) to my backend (localhost:5001).

proxy.conf.json

{
  "/assets/*": {
    "target": "http://localhost:5001/",
    "secure": false,
    "logLevel": "debug",
    "pathRewrite": {"^/assets": ""},
    "changeOrigin": false
  }
}

I successfully run my application with ng serve --proxy-config src\environments\proxy.conf.json. When I access e.g. http://localhost:4200/assets//api/v1/sites/1, it gets rewritten as expected to http://localhost:5001/api/v1/sites/1. However, when requesting http://localhost:4200/assets//api/v1/vehicles, it does not work. They only obvious difference is that the resource vehicles exists under http://localhost:4200 whereas sites/1 does not. When I delete vehicles, the request gets also rewritten.

Is this the expected behaviour: Only rewrite the request if the resource is not available under the original host?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions