npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redirect-rest

v2.2.0

Published

Redirect REST requests to another server

Downloads

4

Readme

redirect-rest

Redirect REST requests to other servers, so you can develop your Javascript app without having to launch the backend server on your machine or worry about CORS.

Getting Started

  • Install the module with: npm install redirect-rest
  • Go to your Javascript app folder
  • Create a .redirect-rest.json file (read more)
  • Launch the server with redirectrest
  • Open http://localhost:4242/ and enjoy your redirects!

Config options

To configure the redirections and everything else for redirectrest, create a .redirect-rest.json file on the root folder of your application.

Inside this JSON file you can have this options:

  • public_path: Path of the assets that will be published on the HTTP server launched by redirectrest. Defaults to: ./

  • html_extensions: Array of file extensions which will be treated as text/html (just in case you are required to have an HTML file with backend extension: PHP, JSP…). Defaults to: ["jsp", "php", "html"]

  • redirection_rules: array that contains the redirection rules to redirect to one or many remote servers. Required. Each item in the array is formed by: - path: path used in the request in order to redirect to the remote server. Required. - remote_url: Base URL of the remote server, where the local requests will be redirected. Required. - proxy: Proxy to be used to make remote server requests. Optional.

  • port: Local server port

  • livereload: Make use of LiveReload to refresh the browser on local changes

  • livereloadPort: Port to be used with LiveReload

For example: Imagine you have a JS app and two REST API services on http://example.com/api/ and http://anotherexample.com/api/. Your .redirect-rest.json file would be:

{
  "html_extensions" : ["aspx", "php", "jsp"],
  "public_path" : "./",
  "redirection_rules" : [
               {
                 "path": "/example",
                 "remote_url": "http://example.com/api"
               },
			   {
                 "path": "/anotherExample",
                 "remote_url": "http://anotherExample.com/api"
               }
			   ]
}

This way you'll have your JS app published under http://localhost:4242/, and requests will be redirected as follows:

  • http://localhost:4242/example/users redirects to: http://example.com/api/users

  • http://localhost:4242/example/roles redirects to: http://example.com/api/roles

  • http://localhost:4242/exmaple/whatever redirects to: http://example.com/api/whatever

  • http://localhost:4242/anotherexample/clients redirects to: http://anotherexample.com/api/clients

  • http://localhost:4242/anoherexample/products redirects to: http://anotherexample.com/api/products

  • http://localhost:4242/anotherexample/whatever redirects to: http://anotherexample.com/api/whatever

ASP.NET, PHP and JSP files will be treated as text/html.

TO-DO

  • [x] Add port, proxy, livereload and livereloadPort config options (v2.1.0, thanks to @howardh)
  • [x] Remove routes. Now all requests are redirected to remote_url (v2.0.0)
  • [x] Remove support for redirections to different remote paths (v1.0.0)
  • [x] Support querystrings (v0.0.9)
  • [x] Redirect local requests to different remote path (v0.0.8)
  • [x] Implement error forwarding to local server from remote server (v0.0.7)
  • [x] Better logging system (v0.0.5)

Acknowledgments

The original idea behind redirect-rest was by @drmillan. He was planning on doing something much more simple, and written in some archaic and obscure language such as PHP.

I couldn't allow that \_(ʘ_ʘ)_/

License

Copyright (c) 2014 Juan G. Hurtado Licensed under the MIT license.