-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdevserver.py
54 lines (39 loc) · 1.26 KB
/
devserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Dev server, busting the HTML5 app cache.
Usage:
devserver.py [<host>] [<port>] [--with-cache]
Options:
-h --help Show this screen.
--with-cache Don't but cache.
"""
import os
import sys
ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
LIBS_DIR = os.path.join(ROOT_DIR, "libs")
sys.path.append(LIBS_DIR)
import docopt
from bottle import (Bottle, run, static_file, abort)
app = Bottle()
arguments = docopt.docopt(__doc__)
@app.route('/')
def index():
return static_file("index.html", root=ROOT_DIR)
if not arguments["--with-cache"]:
@app.route('/cache.manifest', methods=['HEAD', 'GET'])
def bust_cache_manifest():
abort(404, "No cache")
else:
@app.route('/cache.manifest', methods=['HEAD', 'GET'])
def bust_cache_manifest():
response = static_file("cache.manifest", root=ROOT_DIR)
response.headers['Cache-Control'] = 'no-cache'
return response
@app.route('/<filename:path>')
def serve_static(filename):
return static_file(filename, root=ROOT_DIR)
if __name__ == "__main__":
host = arguments["<host>"] or "localhost"
port = int(arguments["<port>"] or 8080)
run(app, host=host, port=port, porreloader=True)