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

solidus-assets-proxy

v2.0.0

Published

This [Solidus](https://github.com/solidusjs/solidus) library provides an easy solution for proxying a site's assets with a CDN or a an image processing service like [imgix](https://www.imgix.com/).

Downloads

6

Readme

SolidusAssetsProxy

This Solidus library provides an easy solution for proxying a site's assets with a CDN or a an image processing service like imgix.

This process can be complex since a site will typically use assets from many sources: local server, Amazon S3, URLs from the site's resources, etc. Making sure all URLs in the site's views use the proxy, and setting up the proxy for all these changing sources is time consuming and prone to error.

SolidusAssetsProxy provides two solutions to this:

  • Utility functions to change all assets URLs to proxy URLs in a Solidus context, to be used in a preprocessor. For example, all URLs matching http://source.com/images/... would be replaced by http://proxy.com/mysite/[encoded asset URL]. No need to setup multiple proxies, a single proxy will take care of all assets sources.
  • A redirects server, that the proxy can use to retrieve the assets data. This server will decode the [encoded asset URL] part of the URL above, validate that it matches one of the configurable whitelisted hosts, and redirect to the asset URL. A single redirects server can be used by multiple Solidus sites, and even when developing a new site.

Installation

$ npm install solidus-assets-proxy --save

Library Usage

Initialization

var SolidusAssetsProxy = require('solidus-assets-proxy');
var assets_proxy = new SolidusAssetsProxy({
  origins: [
    'http://resource1.com/images',
    /http:\/\/resource(?:2|3)\.com\/pictures/ // Note the non-capturing group
  ],
  proxy: 'http://proxy.com'
});

proxyAssets

Replaces all URLs in a string, matching the origins property of the initialization object with the proxy. For example the http://resource1.com/images/bg/red.jpg URL will be changed to http://proxy.com/http%3A%2F%2Fresource1.com%2Fimages%2Fbg%2Fred.jpg.

Note that:

  • The origins property can match only the start of the asset URL.
// Preprocessor
module.exports = function(context) {
  context.some.value = assets_proxy.proxyAssets(context.some.value);

  return context;
};

proxyContextAssets

Runs proxyAssets on all strings in a context, recursively and in place. The second argument is an optional list of paths to limit the changes to.

// Preprocessor
module.exports = function(context) {
  // Replace all string values in the context
  assets_proxy.proxyContextAssets(context);

  // Or only a single resource
  assets_proxy.proxyContextAssets(context.resource1);

  // Or only specific paths
  assets_proxy.proxyContextAssets(context, ['resource1.some.value', 'resource2.some.value']);

  return context;
};

Redirects Server Usage

# solidus-assets-proxy

By default, this will run the server on port 80, and load the redirects whitelist from solidus-assets-proxy-whitelist[.js or .json]. The configuration file can look like:

module.exports = [
  'http://resource1.com/images', // String: URL must start with this
  /http:\/\/resource(2|3)\.com\/pictures/ // RegExp: URL must `match` this
];

The port and configuration file path can be changed with:

# PORT=123 solidus-assets-proxy /path/my-list.json

If the request URL path is / or /status, the response will be 200 OK. For any other URL, the whole path (minus the first /) will be decoded, and tested agains the whitelist. If it matches, the response will be a 302 redirect to the decoded URL, else the response will be 406 Not Acceptable.

Building

$ npm run build

Testing

Node and automated browser tests

$ npm run test

Node test

$ npm run node-test

Automated browser test

$ npm run browser-test

Manual browser test

$ npm run test-server

Then access http://localhost:8081/test/browser/test.html in your browser