Last active
December 22, 2015 04:49
-
-
Save AbsoluteDestiny/6419753 to your computer and use it in GitHub Desktop.
Single file server example using bottle.py
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
from __future__ import print_function | |
import os | |
import sys | |
from bottle import Bottle, static_file, run | |
if __name__ == "__main__" and len(sys.argv) > 1: | |
f = os.path.abspath(sys.argv[1]) | |
if not os.path.exists(f): | |
raise Exception("File not found: {}".format(f)) | |
path, filename = os.path.split(os.path.abspath(f)) | |
app = Bottle() | |
@app.route('/') | |
def fileserve(): | |
return static_file(filename, root=path) | |
run(app, host='localhost', port=8080) | |
else: | |
print("Usage: singleserve.py /path/to/file.ext") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment