Created
April 6, 2014 03:03
-
-
Save vitorbritto/10000952 to your computer and use it in GitHub Desktop.
Bash function to initialise a static web server with Python or PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------------------------------------------------- | |
# Start an HTTP server from a directory, optionally specifying the port | |
# ---------------------------------------------------------------------- | |
pyserver() { | |
local port="${1:-8000}" | |
sleep 1 && open "http://localhost:${port}/" & | |
# Set the default Content-Type to `text/plain` instead of `application/octet-stream` | |
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files) | |
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port" | |
} | |
# ------------------------------------------------------------------- | |
# Start a PHP server from a directory, optionally specifying the port | |
# ------------------------------------------------------------------- | |
phpserver() { | |
local port="${1:-4000}" | |
local ip=$(ipconfig getifaddr en1) | |
sleep 1 && open "http://${ip}:${port}/" & | |
php -S "${ip}:${port}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how do i use this on a windows machine, I'm able to run it on a apple machine but i cant get it to work on a windows