Skip to content

Instantly share code, notes, and snippets.

@AbsoluteDestiny
Last active December 22, 2015 04:49
Show Gist options
  • Save AbsoluteDestiny/6419753 to your computer and use it in GitHub Desktop.
Save AbsoluteDestiny/6419753 to your computer and use it in GitHub Desktop.
Single file server example using bottle.py
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