Last active
May 22, 2019 14:34
-
-
Save eastlondoner/e136e495822687b37ecb115b249e7f06 to your computer and use it in GitHub Desktop.
Use whichever python version is available to start a simple http server that serves the current directory.
This file contains hidden or 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
| #!/usr/bin/env bash | |
| set -e | |
| # Example usage: `cd web && PORT=8000 ./serve.sh` | |
| # Default to 8080 if no PORT is specified | |
| PORT="${PORT:-8080}" | |
| # Check which python major version is available and start a simple http server accordingly | |
| if [[ "$(python -c 'import sys; print(sys.version_info[0])')" == "3"* ]]; then | |
| python -m http.server "${PORT}" | |
| else | |
| python -m SimpleHTTPServer "${PORT}" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment