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

remote

v0.2.6

Published

Work on client-side files with a remote API server transparently

Downloads

5,672

Readme

Remote

Remote is a simple CLI tool that enables you to work in local files while consuming an API from a remote server. An easy reverse proxy in Node, if you will.

If you'd like, it can also start a simple local server for your files.

Simply specify

  • the address of your local files server, or where I should start one
  • the address of your remote API
  • the address of where to start a reverse proxy
  • a directory, if you want me to start a local server
  • some regex rules that define which files to serve locally, which to fetch from the remote host
  • optionally, you can map requests to specific files with the mappings option

It aims to solve the dreaded cross domain request problem, so you can freely ajax like you have a local server-side.

Install

npm install -g remote

Quickstart

After installing, create a remote.json configuration file (check the example folder) and simply call remote.

Usage - command line

remote [options]

	Options:

		-h, --help                output usage information
		-V, --version             output the version number
		-d, --directory [path]    Path to a local folder. If defined, will serve files at server address. [undefined]
		-r, --remote [host:port]  Address of the remote API [localhost:80]
		-p, --proxy [host:port]   Address of the reverse proxy server [localhost:9001]
		-s, --server [host:port]  Address of the static file server [localhost:9000]
		-m, --mapping             Whether to use the mapping rules [false]
		-f, --file [remote.json]  Specific configuration file [remote.json]

Usage - configuration file (remote.json)

See the example configuration file at the example folder.

Read on for the possible options for your remote.json file.

Bounces

This is the simplest remote.json, with some bounce rules defined:

{
	"directory" : "./src/",
	"remote" : {"host": "remote-api-host.com", "port": 80},
	"bounces" : [
	    "public/.*",
	    "assets/.*"
	]
}

In this case, any call to localhost:3000/public/(...) or localhost:3000/assets/(...) will be bounced to your local files under ./src/. Other URL's will be forwarded to remote-api-host.com

Headers

You may wish to send along some headers with your request. For example:

{
		"directory" : "./src/",
		"remote" : {"host": "remote-api-host.com", "port": 80},
		"headers": {
				"Host": "remote-api-host.com",
				"X-Secret-Header" : "awesome"
			},
		"bounces" : [
				"public/.*",
				"assets/.*"
			]
}

These will be added to every request made by remote.

Mappings

A mapping is like a bounce rule, only more specific. You define what you want served given a request URL. For example:

{
	"directory" : "./src/",
	"remote" : {"host": "remote-api-host.com", "port": 80},
	"headers": {
			"Host": "remote-api-host.com",
			"X-Secret-Header" : "awesome"
	},
	"bounces" : [
	    "public/.*",
	    "assets/.*"
	],
    "mapping": true,
    "mappings": {
        ".*/api/users/1/remove": {"result": "ok"},
        ".*/api/users/.*":"./test/mocks/users-mock.json",
        ".*/files/.*":"./test/files/",
        ".*/public/js/awesome.js":"./src/special/path/awesome-2.js"
    }
}

As you can see, mappings can be:

  • A JSON object.
  • A path to any file.
  • A path to any directory (Remote will locate the requested file in the directory).

When any of these URL's are requested, remote will serve the given resource.

Note that mappings take precedence over bounce rules!

You can disable all mappings setting mapping to false.

Bounce to remote

If you like to keep things complicated, you may use the bounceToRemote: true option in your configuration file. This will invert the bounces rules, so they will actually bounce to the remote API. All other requests will be forwarded to the local server.

Other notes

Command line options take precedence over remote.json options. Also, any command line option may be specified in the json configuration file. Have fun!


Note for Mac OS X users (or: what to do when I get EMFILE errors)

OS X has a arbitrarily low limit for the amount of files that a process can open of 256. Use the ulimit command to check your current limit. For sites with large amounts of files, or in any situation when encountering EMFILE errors, simply issue:

ulimit -n 2048

Or any such large value, before turning on remote.


Changelog:

v 0.2.6:

  • Ignores query string on mapping.
  • Starting unit tests with jasmine-node.

v 0.2.5:

  • Serves images correctly. Really, this time.
  • Accepts mapping with 'http://' to change to arbitrary host.

v 0.2.4:

  • Serves images correctly (utf8 issue fix, thanks Augusto).

v 0.2.3:

  • Accepts directory for mappings.

v 0.2.1:

  • File update and options scope fix.
  • Mappings should work now when applied in a file.

v 0.2.0:

  • Breaking changes in API. Old remote.json files wont work.
  • Better options syntax
  • Bring you own local server. Now you can use remote as a reverse proxy, only.
  • Many fixes.

v 0.1.0:

  • Major rewrite. Nothing of note before this ;)
  • Using nodejitsu's http-proxy
  • Add the capability to map arbitrary url to arbitrary files or JSON
  • Add the capability to add request headers