Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add alias to bash_profile to get a quick http server anywhere. Just type H to serve current directory.
# http://stackoverflow.com/a/12269225/670023
# Binds to localhost
alias H="echo 'Serving HTTP on 127.0.0.1 port 8000 ...'; python -c 'import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer((\"127.0.0.1\", 8000), shs.SimpleHTTPRequestHandler).serve_forever()'"
@lukasgraf

This comment has been minimized.

Copy link

commented Oct 21, 2014

Here's a version with an optional port argument (defaulting to 8000):

http () {
    PORT=${1:-8000}
    echo "Serving HTTP on 127.0.0.1 port ${PORT} ..."
    python -c "import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer(('127.0.0.1', ${PORT}), shs.SimpleHTTPRequestHandler).serve_forever()"
}
alias H=http
@cmawhorter

This comment has been minimized.

Copy link
Owner Author

commented Oct 22, 2014

nice! i don't know why i didn't consider this sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.