pmer / local-cdn

Provide a private, local mirror for the world's CDNs
MIT License
0 stars 0 forks source link

local-cdn

An HTTP proxy server designed to be used for only a small number of sites on the Internet. Probably for content that almost never changes, such as the CDNs that carry jQuery, etc.

Setup

Install the dependencies.

npm install

Make the data directory and create a whitelist.txt with a list of domains that you want to mirror.

mkdir -p data/fs
echo bootstrapcdn.com >> whitelist.txt

If you want to support HTTPS resources then you'll need to make a TLS certificate for local-cdn to use. Make sure you install it into your browser or OS so that it's accepted. Save the unencrypted private key as key.pem and the certificate as cert.pem in the local-cdn's top directory.

Start the server.

node src

The server listens on ports 80 and 443. Any incoming requests whose domain isn't within the white list are immediately discarded and are given HTTP 404. Use the special domain * in the white list to allow all requests.

For each request that comes through, local-cdn will check to see if it's already downloaded it. If it has, it returns that. Otherwise, it goes ahead and downloads an initial version of the file, saves it, and replies with that.

Tell your web browser to use local-cdn for the domains you want. You may want to use your hosts file for this, but any method is fine.

echo 127.0.0.1 bootstrapcdn.com >> /etc/hosts

Remove or comment out the entries from the hosts file later to restore previous behavior and allow your system to connect directly to those sites.

How it works

Right now there is only a rough filesystem backing for saved content. HTTP data is saved in the ./data/fs/ directory.

At the moment we never check to see if the content was updated on the remote server so once a URL is mirrored to your local computer it is permanent. This makes it really only applicable for mirroring domains in which URL content is not expected to change.

Project maturity

Pre-alpha. Use at your own risk.

How to contribute

Report issues on Github or make pull requests.