Skip to content

Instantly share code, notes, and snippets.

@andymason
Last active March 1, 2016 12:10
Show Gist options
  • Save andymason/2188fdda7a3f60d846c6 to your computer and use it in GitHub Desktop.
Save andymason/2188fdda7a3f60d846c6 to your computer and use it in GitHub Desktop.
How to preview localhost content in Composer

Using localhost in composer was an extremely useful way to develop locally while seeing what interactives look like within guardian pages. Unfortunately composer only accepts HTTPS links now, which is a good thing but makes local dev'ing a bit more difficult.

Now to test from localhost you'll need to serve content over a secure connection which means self-signed certs. Here's a quick and dirty way to do that

1# Create a folder to store the keys

  mkdir ~/ssl

2# Generate SSL keys. Enter a password for now, we'll get rid of it next then just skip over all the other questions

openssl req -x509 -newkey rsa:2048 -keyout ~/ssl/key.pem -out ~/ssl/cert.pem -days 999

3# Get rid of that password so it doesn't always ask for it

openssl rsa -in ~/ssl/key.pem -out ~/ssl/key.pem

4# Install / update the useful node http-server

sudo npm install http-server -g

5# Run the server in your interactive project folder

http-server --cors --ssl --cert ~/ssl/cert.pem --key ~/ssl/key.pem

6# You might want to alias that last command into something smaller by adding it to your ~/.bash_profile eg

echo 'alias webserver="http-server --ssl --cert ~/ssl/cert.pem --key ~/ssl/key.pem"' >> ~/.bash_profile

Enjoy.

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