diff --git a/offline_host.py b/offline_host.py new file mode 100644 index 0000000000000000000000000000000000000000..1cb3f134640874db0820fe40c501c52b89929430 --- /dev/null +++ b/offline_host.py @@ -0,0 +1,32 @@ +from bottle import get, post, request, response, redirect, route, run, static_file +import os +import os.path as osp + +host='localhost' +port=5000 + +@route('/') +def redir_index(): + return redirect('/index.html') + +ext_mimetypes = { + '.png': 'image/png', + '.jpg': 'image/jpeg', + '.css': 'text/css', + '.js': 'text/javascript', + '.html': 'text/html', + '.xml': 'application/xml' +} + +@route('/<filename:path>') +def statics(filename): + ext = osp.splitext(filename)[-1] + + try: + mimetype = ext_mimetypes[ext] + except KeyError: + mimetype = 'text/plain' + + return static_file(filename, root=os.getcwd(), mimetype=mimetype) + +run(host=host, port=port, reloader=True)