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

proxey

v0.4.2

Published

Enables frontend developers to run their webapps in a nodejs proxy without worrying about cors or creating server side coding

Downloads

18

Readme

Proxey

Nodejs server proxy for web app developers

Instalation

$ npm install proxey

How to Use

  • rootFolder: the web app folder;
  • rootDocument: document to be rendered as the main html;
  • port: port to run, default is 5000 (optional);
  • vars: a json containing additional headers to be sent in each proxy request (optional);
    • if the var value will be inserted in all proxy requests if it is a string;
    • the value can be a json with some opttions, so it can be used dynamically;
  • proxyUrl: a path to be used as the proxy url to send json requests, default is "/proxy" (optional);
  • routes: a json containing a path and its relative html view file to render. If the '/' route is not set, it will use the rootDocument prop (default index.html) as the default view file;
  • charset: the charset to be used in the proxy responses, default is "utf-8".
  • proxy: a json containg static proxy key:value url. It will detect every request sent to the "key" url to the "value" url.

Sample with routes:

var server = require('proxey');

server.run({
	rootFolder: './app',
	port: 5000,
	proxyUrl: '/proxy',
	vars: {
		'X-Api-Token': '12345'
	},
	routes: {
		'/': 'home.html',
		'/users': 'users.html',
		'/api/users',: 'users.json'
	},
	charset: 'utf-8'
});

Sample without routes:

var server = require('proxey');

server.run({
	rootFolder: './app',
	rootDocument: 'index.html',
	port: 5000,
	proxyUrl: '/proxy',
	vars: {
		'X-Api-Token': '12345'
	}
});

Sample with custom headers:

var server = require('proxey');

server.run({
	rootFolder: './app',
	rootDocument: 'index.html',
	port: 5000,
	proxyUrl: '/proxy',
	vars: {
		'X-Api-Token': '12345',
		'x-whatever': {
			'real': 'X-Whatever' //proxy will use this header name,
			'value': 'header-value'
		}
	}
});

Sample with json proxy:

var server = require('proxey');

server.run({
	rootFolder: './app',
	rootDocument: 'index.html',
	port: 5000,
	proxy: {
		"/api": "http://api.server.com", // /api/users will become http://api.server.com/users
		"/dev-api": "http://api.dev.server.com", // /dev-api/data will become http://api.dev.server.com/data
	},
	vars: {
		'X-Api-Token': '12345'
	}
});

When running the server, all resource files (css, js, imgs, etc) can be used with a relative path (css/styles.css).

The Proxy

Every request sent to the proxy url needs to have an encoded url patameter:

'/proxy?url=' + encodeURIComponent('http://www.google.com');

Every http request sent to this url will be forwarded to the given "url" query string param, with all the headers, parameters and request body of the ajax method:

//sample jquery request
$.get('/proxy?url=' + encodeURIComponent('http://www.google.com'));

//jquery with custom headers
var url = 'http://www.google.com';
var headers = {
	'x-whatever' = '__x-whatever__' // __ to use dynamic values
};
$.ajax({
	url: '/proxy?url=' + encodeURIComponent(url),
	headers: headers
})
.always(function (data) {
	console.log(data);
});

The proxy will intenfity the "x-whatever" due to its name and the __x-whatever__ which indicates proxey to use the custom header:

X-Whatever: header-value

The MIT License (MIT)

Copyright (c) 2015 Leonardo Rossetti [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.