Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The path-matching behaviour ofdevServer.proxy is different fromhttp-proxy-middleware#7432

RexSkz started this conversation inGeneral
Discussion options

The matching behaviour and the docs

Assume there's a config aboutdevServer.proxy:

{'/bar':{target:'<url>',}}

It can match not only the path/bar/123 (as expected) but also/foo/bar (not expected).

The English version of the document says that we should use^/bar:

image

But the Chinese version gives us the code that uses just/bar:

image

Why it is not as expected

By default,/xxx is meant to match the paths that start with/xxx, not the paths that contains/xxx.

Various RESTful frameworks (Express, Koa, Gin, Django, Spring) and web servers (Nginx, Apache), as well ashttp-proxy-middleware which is used byvue-cli, follow this rule. The well-known librarywebpack-dev-server also follows this rule.

Why it happens

The cause is atprepareProxy.js#L73:

if(context){// Explicit context, e.g. /apireturnpathname.match(context)}

TheString.prototype.match(re) function receives a parameterre; ifre is not RegExp and does not have aSymbol.match method, it will be converted to a RegExp by usingnew RegExp(re).

So we are actually executing'/foo/bar'.match(/\/bar/), it works.

What to do then

Considering this project is in maintenance mode, the behaviour may not be changed; but maybe we can make it clearer in the document.

  1. The Chinese version of the document should catch up with the English one.
  2. A text about the slight difference betweenvue-cli andhttp-proxy-middleware should be added to the document.
You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
1 participant
@RexSkz

[8]ページ先頭

©2009-2025 Movatter.jp