lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.22k stars 86 forks source link

Rewrite wildcard does not create the match #175

Closed tkosci closed 2 years ago

tkosci commented 2 years ago

Hello,

I am facing issue with rewrite wildcard.

When I use:

ws --port 8080 --spa index.html --directory build --rewrite "/api/(.*) -> http://localhost:5000/api/$1" --verbose.include middleware.rewrite

The urls do not match as seen in screenshot below:

image

However, in debugging tool the wildcard matches just fine: npx lws-rewrite '/api/(.*)' 'http://localhost:5000/api/$1' '/api/count_data/' -> http://localhost:5000/api/count_data/

Any idea what is the issue here? Thanks

75lb commented 2 years ago

Hi, are you on *nix? If so, always use single quotes as double-quotes have special meaning with strings that contain $ (variable expansion)..

try this instead (no double quotes)

ws --port 8080 --spa index.html --directory build --rewrite '/api/(.*) -> http://localhost:5000/api/$1' --verbose.include middleware.rewrite
75lb commented 2 years ago

the clue was in your verbose output.. I could see the from string was set correctly but the middleware had not received the full to string (missing $1 at the end)

{
  'middleware.rewrite.config': {
    rewrite: [ { from: '/api/(.*)', to: 'http://localhost:5000/api/' } ]
  }
}
tkosci commented 2 years ago

Thank you, that fixed it for me! It was the double quotes, now the dollar sign symbol with number is visible in the verbose output as well.