Skip to content

Instantly share code, notes, and snippets.

@crash7
Last active August 29, 2015 14:23
Show Gist options
  • Save crash7/7a9c30986c7d998f7f61 to your computer and use it in GitHub Desktop.
Save crash7/7a9c30986c7d998f7f61 to your computer and use it in GitHub Desktop.
Replicate secure cdn using a normal cdn as fallback

Replicate secure cdn using a normal cdn as fallback

1- Install http-server nodejs module

sudo npm install -g http-server

2- Create a folder for your files

mkdir replicated-cdn
cd replicated-cdn

3- Create a self-signed certificate

openssl genrsa -out key.pem 2048
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem

4- Add the secure cdn host in your /etc/hosts

127.0.0.1   scdn.example.com

5- Launch the local server

http-server --ssl -p 443 --cors --proxy http://cdn.example.com/

On MacOS you probably need to use sudo

If the request cannot be resolved, it will try to load the files from http://cdn.example.com/

If you create the necessary files, it will load your filel :)

Based on this article: https://docs.nodejitsu.com/articles/HTTP/servers/how-to-create-a-HTTPS-server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment