You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
But the Chinese version gives us the code that uses just /bar:
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 as http-proxy-middleware which is used by vue-cli, follow this rule. The well-known library webpack-dev-server also follows this rule.
if(context){// Explicit context, e.g. /apireturnpathname.match(context)}
The String.prototype.match(re) function receives a parameter re; if re is not RegExp and does not have a Symbol.match method, it will be converted to a RegExp by using new 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.
The Chinese version of the document should catch up with the English one.
A text about the slight difference between vue-cli and http-proxy-middleware should be added to the document.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The matching behaviour and the docs
Assume there's a config about
devServer.proxy
: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
:But the Chinese version gives us the code that uses just
/bar
: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 as
http-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 at prepareProxy.js#L73:
The
String.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.
vue-cli
andhttp-proxy-middleware
should be added to the document.Beta Was this translation helpful? Give feedback.
All reactions