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

martinez

v0.0.6

Published

Mix local and remote resources

Downloads

14

Readme

martinez

Mix local and remote resources. Simple http server that allows to combine local directories with a remote resource.

You can specify any number of local directories, the server will try to match each request to a local resource, in the order they were added, or forward to the remote address, if specified.

Installation

$ npm install --global martinez

Options

  • -l, --local target/, config local: Local directory. You can provide more than one and requests will be looked up in the order they were added. This is required. For configuring multiple entries in the configuration object, use an array.
  • -a, --address 10.101.1.101, config address: Local address in which to listen for requests. Defaults to '0.0.0.0'.
  • -p, --port 80, config port: Local port in which to listen for requests. Defaults to 8080.
  • -r, --remote https://example.com/, config remote: Remote URL to forward all non-local resources (http or https).
  • --strip-cookie-domain, config stripCookieDomain: On forwarded requests, strip the Domain from any cookies set. This will allow the cookie to be set for any subsequent requests. Defaults to true.
  • -x, --proxy http://localhost:3128, config proxy: Proxy to use to connect to the remote resource.
  • --allow-invalid-cert, config allowInvalidCert: Allows self-signed SSL certificates. Defaults to false.
  • --config config.js: Load a configuration from the given file. All options can be configured in a file. Any options specified in the command line will override options in the configuration file.
  • --help: Shows the help screen and exits.
  • --version: Shows the current version number and exits.

Examples

Basic local dev server

Serve resources from dist/:

$ martinez --local dist

Basic local + remote dev server

Serve resources from dist/, forward everything else to https://mydevserver.example.com/:

$ martinez --local dist --remote https://mydevserver.example.com

Proxied remote dev server

Serve resources from build/, forward everything else to http://dev.example.com and use a debugging proxy such as Charles to inspect the remote requests (Charles uses self-signed certs):

$ martinez --local build --remote http://dev.example.com/ --proxy http://localhost:8888/ --allow-invalid-cert

Remote dev server with content rewriting

Serve resources from target/, forward everything else to http://dev.example.com and use the configuration entries in martinez.config.js to rewrite certain response bodies:

$ martinez --local target/ --remote http://dev.example.com/ --config martinez.config.js

Usage

Content rewriting

Content rewriting is controlled via entries in the rewrite section in the configuration object. Each entry is keyed by the path of the request and the value is a function that receives the body of the response as a String and returns the new body that will be sent to the client.

This can be used to change entries in configuration files, replace remote paths with local paths in script tags, etc.

This example would rewrite the response from any request to /api/v1/manifest and change any instances of 'https://endpoint.example.com' to 'http://localhost/endpoint'.

module.exports = {
  rewrite: {
    '/api/v1/manifest': function rewriteManifest(content) {
      return content.replace(/https:\/\/endpoint.example.com/gi, 'http://localhost/endpoint')
    }
  }
}

Currently the proxy only rewrites content for exact matches on the path.