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

x-proxy

v1.0.1

Published

helpers to perfrom url rewriting and reverse rewriting for a proxy target

Downloads

11

Readme

x-proxy

Build Status](https://travis-ci.org/x-component/x-proxy)

./proxy.js

url

x-proxy

This module provides helper functions to map urls from an external client representations to urls as used bay a backend server. It also supports the reverse mapping back from urls of the backend server to external client urls.

The following diagram depicts a proxy mounting the backend server at the mount point '/xyz'

               +---------+        +----------------------------------+
  client ----->|  proxy  |------->| target backend server            |
               |  mount: |        | url:                             |
               |  '/xyz' |        | http://server:8080/target/path   |
               +---------+        +----------------------------------+

The extenral url /xyz/a?b=c seen by a client of the proxy, should thus be mapped to http://server:8080/target/path/a?b=c

Note: the external url representation takes care about x-forwarded-host headers etc.

  var proxy = require('x-proxy');
  var mount = '/xyz';
  var prx = req.proxy = proxy(req,{url:'http://server:8080/target/path'},mount);
  // prx now provide mapping functions within the context of this request and the given target url

** request / backend specific helpers: **

prx.internal( url )

test if an url is part of the proxy backend server, thus an internal location, or is just link to some external location (false) for internal locations a object is returned : {secure_switch:false} or {secure_switch:true}. secure_switch indicates if it is an internal location but the protocoll is changed. p.e. to jump to a https version of the location

prx.url( url )

maps an url with mount of the server to an url in terms of the backend server

prx.reverse( url, with_http_server_port )

maps an url of the backen server to an url for the client. Use with_http_server_port=true in case you need an absolute url. p.e. for lcoation headers.

prx.relativize( url )

transforms an (absolute) backend server url to a extrnal valid relative url. This allows to rewrite html content to relattive urls, such they stay valid in a chain of proxies.

prx.resolve( relative_url , with_http_server_port )

relsolve a releative url to an external absolute url. Use with_http_server_port=true in case you need an absolute url with server and port.

** global helpers: **

proxy.relativize( base, path )

for a prefix and a an absolute path return a relative path: p.e. base:'/a/b/c/d', path:'/a/b/e', result: '../e'

proxy.absolutize( req, relative_path, with_http_server_port )

return an absolute url for this request, optionally with protocol, server and port.

proxy.externalize( req, relative_url )

create an absolute url suitable for a client browser, thus using host and x-forwarded host headerss

proxy.internalize( req, relative_url )

create an absolute url suitable for this server internally, NOT using x-forwarded-host etc.

proxy.secure( req )

return an absolute secure version of the current request url for a client