简体   繁体   中英

How does `^` mean in Webpack DevServer Proxy pathRewrite

I'm trying to understand theWebpack DevServer Proxy documentation .

My goal is to proxy any paths without.html to the corresponing .html file. Examples: /foo -> /foo.html and /bar -> /bar.html

I guess, I need to use pathRewrites . The documentation example suggests to rewrite the path with pathRewrite: {'^/api': ''} .

The syntax (of the first argument) is not yet clear to me: What is the meaning of the caret ( ^ ) character? Is it a Regexp? Is the syntax documentet somewhere?

Found it:

The dev-server makes use of the powerful http-proxy-middleware package.

that defines

Object-keys will be used as RegExp to match paths.

-> yes, it's a Regexp.

I was trying to achieve the exact same functionality as you. For the future viewers of this question: http-proxy-middleware does not support capture groups https://github.com/chimurai/http-proxy-middleware/issues/271 as per now.

So you are forced to use a custom rewrite function that appends the extension to your path as stated here: https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md#custom-rewrite-function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM