lwsjs / local-web-server

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

How can I add rewrite-rules? #20

Closed markusbrunner-design closed 8 years ago

markusbrunner-design commented 8 years ago

Like in the npm-server "web-server-rewrite" I really need http-rewrite-rules with regular expressions. But:

  1. I really like your local-web-server
  2. I can't get the web-server-rewrite to work because of problems with the execSync-Dependency

What for is this? It's especially for services which need to be rewritten to another url in local and live-environment, e.g.:

rewrites

 {
    "localhost": {
      "(.*)(/users/)(.*)": "http://myserver1.mw.domain.lan:10080/middleware1/$3",
      "(.*)(/auth/)(.*)": "http://myserver2.mw.domain.lan:10080/auth-service/$3"
    },
   "domain.de": {
    ...
   }
 }

This would be very helpful - and if you include the keyword "rewrite" in your descriptions, this would definitely boost your server-implementation!

Regards Markus

75lb commented 8 years ago

i see.. yes, that looks very useful - i will implement, thanks.

75lb commented 8 years ago

implemented in the new version.. feedback welcome!

$ npm install -g local-web-server@^1.0.0-alpha.1
markusbrunner-design commented 8 years ago

Hey,

at first I wanna thank you for implementing this issue - that's really cool!

Unfortunately the current "configuration" isn't working for me, because I need port-numbers in my rewrite-rule: => "http://my.server.lan:10080/myservice/$1" but they are used via ":" for constants?

Regards Markus

75lb commented 8 years ago

reproduced, fixing..

75lb commented 8 years ago

i found and fixed an issue regarding rewrite "to" addresses containing port numbers.. can you install 1.0.0-alpha.5 and try again please?

i successfully tested it with this rewrite rule: (all paths under /yeah successfully proxied)

$ ws --rewrite '/yeah/* -> http://localhost:9000/$1'
markusbrunner-design commented 8 years ago

the port-numbers are working now, great!

but it seems like the new rewrite-rule doesn't transfer the query string parameters - which is also necessary for my case and in general

Regards Markus

75lb commented 8 years ago

thanks again - try the new release, version v1.0.0-alpha.6 :+1:

markusbrunner-design commented 8 years ago

very, very nice! now it works for my use-case!

That's very helpful 75lb!

Regards Markus

75lb commented 8 years ago

good.. let me know if you have any more issues..