lwsjs / local-web-server

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

rewrite middleware doesn't treat pattern `:0` correctly #70

Closed asa-taka closed 7 years ago

asa-taka commented 7 years ago

Hi, I'm very helped by local-web-server everyday.

I found a strange behavior with rewrite feature when I configure lws.config.js as

module.exports = {
  port: 8000,
  rewrite: [
    { from: "/api/*", "to": "http://localhost:9000/$1" }
  ]
}

and I start ws and send request to localhost:8000/api/messages?time=2017-01-01T12:00, then I found a strange replacement in ws verbose logs

{ 'middleware.rewrite.proxy': 
   { from: '/api/messages?time=2017-01-01T12:00',
     to: 'http://localhost:9000/messages?time=2017-01-01T12messages0' } }

Near :0 in the original time-string, a string messages (seems to be captured by *) appears again.

I also tried to send another string localhost:8000/api/messages?time=2017-01-01T12:10 then ws logs

{ 'middleware.rewrite.proxy': 
   { from: '/api/messages?time=2017-01-01T12:10',
     to: 'http://localhost:9000/messages?time=2017-01-01T12:10' } }

It looks like a correct replacement, so I think the pattern :0 causes the broken replacement.

75lb commented 7 years ago

thanks for letting me know! Fixed and released in local-web-server v2.2.4.

Let me know if you find anything else 👍