Created
March 15, 2014 06:59
-
-
Save mtayseer/9562792 to your computer and use it in GitHub Desktop.
Static files server using Bottle web framework
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
'''Static files server using Bottle web framework''' | |
# You can use the command `python -m SimpleHTTPServer`, but when you want to | |
# do more, use this snippet | |
from bottle import route, run, static_file | |
@route('/') | |
@route('/<path:path>') | |
def serve(path='index.html'): | |
response = static_file(path, root=OUTPUT_ROOT) | |
# if the user wants a directory, I search for index pages | |
if path.endswith('/') and response.status_code == 404: | |
for file in ['index.html', 'index.htm']: | |
response = static_file(path + file, root=OUTPUT_ROOT) | |
if response.status_code != 404: | |
return response | |
return response | |
run(host='localhost', port=8080, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment