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

integration-proxy

v1.1.2

Published

Express middleware for conditional reverse-proxy to enable integrated front-end web development.

Downloads

8

Readme

Integration Proxy

An integration proxy is a reverse proxy that transforms responses (headers and bodies) to emulate an integrated environment in a local Express server.

As a front-end web developer, you want to build and test your static assets in a context that mostly closely matches the environment to which they will eventually be deployed.

Traditional solutions to this problem typically involve cloning the integrated environment. Then, either you run it locally and edit files internally to the system, or you run it in a sandbox to which you transfer files via Samba or FTP. Unfortunately, cloning environments is often complicated, and running locally may require special infrastructure or proprietary tools. Even with a sandbox, transferring files adds load to a network and sometimes involves extra steps that impede development productivity.

By running an integration proxy as part of your Node-based development stack, you can edit files locally in a lightweight stack as long as necessary and transfer files only for deployments.

Usage

var express = require('express');
var integrationProxy = require('integration-proxy');

var app = express();

app.use('/', integrationProxy({
	target: 'http://example.com',
	transform: function(url) {
		return url.replace('http://example.com', 'http://localhost');
	}
});

API

integrationProxy(options) --> express.Router

options.target (String) required

The target option is the URL of the remote server.

options.transform (Function) optional

The transform option is a function that takes a string and returns a string. It should be defined so as to fix origins in URL's that occur in headers and HTML bodies from the remote target server.

The reason it is a function rather than a simple replacement string is because you may want to run multiple proxies in parallel that transform content interlinking several different origins. You may want to use a more general pattern to replace subdomains or non-SSL versus SSL.

Features

In addition to relaying requests and responses between local and remote hosts (as with a basic http-proxy configuration), integration-proxy also:

  • removes content-length headers, if any, to prevent truncation in case HTML changes result in different lengths
  • modifies set-cookie headers by removing "Domain" and "Secure" restrictions, to allow clients to accept cookies in spite of differences between local and remote origins
  • applies transform to:
    • origin header
    • location headers
    • A@HREF attributes
    • FORM@ACTION attributes

Caveats

NOTE: To ensure proper system security when running any reverse proxy, always ensure that access to the proxy is at least as secure as its target, if not more. This module is intended as a development tool and should only ever need to be run inside an organizationally restricted network for a development team.

Example: Static Injection

To emulate a remote host but serve static assets from a local directory:

var express = require('express');
var integrationProxy = require('integration-proxy');

var app = express();

// serve static assets from local file system
app.use('/assets', express.static('pub/assets'));

// serve all other requests via proxy
app.use('/', integrationProxy({
	target: 'http://example.com',
	transform: function(url) {
		return url.replace('http://example.com', 'http://localhost');
	}
});

app.listen(80);

Example: Service Injection

To run a local host but proxy a remote API:

var express = require('express');
var integrationProxy = require('integration-proxy');

var app = express();

app.use('/api', integrationProxy({
	target: 'http://example.com/api'
});

// ...

app.listen(80);

Example: Context Alias

To change the context of certain requests:

var express = require('express');
var integrationProxy = require('integration-proxy');

var app = express();

app.use('/account', integrationProxy({
	target: 'http://example.com/test-account',
	transform: function(url) {
		return url.replace('http://example.com', 'http://localhost');
	}
});

app.listen(80);