Skip to content

Instantly share code, notes, and snippets.

@kevin-smets
Last active October 21, 2017 06:09
Show Gist options
  • Save kevin-smets/17446bc5433e834f6a9445bdcb75bcb8 to your computer and use it in GitHub Desktop.
Save kevin-smets/17446bc5433e834f6a9445bdcb75bcb8 to your computer and use it in GitHub Desktop.
One liners for CLI asset servers

Https / Http2

Caddy

macOS: brew install caddy

caddy --conf=<( echo -e ':8080\ntls self_signed' )

Make sure to use https://, otherwise you'll download a.. download file. Since it's self signed, you'll need to ignore any security warnings in order to continue.

This alert be skipped in Chrome by either typing "badidea" when the alert is showing. This is a one off measure, restarting the server will trigger the alert again. It can be set permanently by checking the flag under chrome://flags/#allow-insecure-localhost (requires a Chrome restart).

Props to @bgotink

Http / Http1

Docker

macOS: brew cask install docker

docker run www -it -p "8080:80" -v "$(pwd)":/usr/local/apache2/htdocs/ httpd:2.4-alpine

Running it in the background:

WWW=$(docker run -dit -p "8080:80" -v "$(pwd)":/var/www/html lkwg82/h2o-http2-server)

To terminate, run docker attach $WWW and hit Ctrl + C.

Python2

python -m SimpleHTTPServer 8080

Serve another dir (this pattern applies to all other cmds of course):

pushd out/www; python -m SimpleHTTPServer 8080; popd

If you do not want to expose the assets to the entire network:

python -c 'import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer(("$(ipconfig getifaddr en0)", 8080), shs.SimpleHTTPRequestHandler).serve_forever()'

Python3

python -m http.server 8080

PHP (5+)

php -S localhost:8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment