You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0 KiB

8 years ago
  1. ## URL rewriting
  2. Your application requested `/css/style.css` but it's stored at `/build/css/style.css`. To avoid a 404 you need a rewrite rule:
  3. ```sh
  4. $ ws --rewrite '/css/style.css -> /build/css/style.css'
  5. ```
  6. Or, more generally (matching any stylesheet under `/css`):
  7. ```sh
  8. $ ws --rewrite '/css/:stylesheet -> /build/css/:stylesheet'
  9. ```
  10. With a deep CSS directory structure it may be easier to mount the entire contents of `/build/css` to the `/css` path:
  11. ```sh
  12. $ ws --rewrite '/css/* -> /build/css/$1'
  13. ```
  14. this rewrites `/css/a` as `/build/css/a`, `/css/a/b/c` as `/build/css/a/b/c` etc.
  15. ### Proxied requests
  16. If the `to` URL contains a remote host, local-web-server will act as a proxy - fetching and responding with the remote resource.
  17. Mount the npm registry locally:
  18. ```sh
  19. $ ws --rewrite '/npm/* -> http://registry.npmjs.org/$1'
  20. ```
  21. Map local requests for repo data to the Github API:
  22. ```sh
  23. $ ws --rewrite '/:user/repos/:name -> https://api.github.com/repos/:user/:name'
  24. ```
  25. [Example](https://github.com/75lb/local-web-server/tree/master/example/rewrite).