-
Notifications
You must be signed in to change notification settings - Fork 29
/
run.py
57 lines (48 loc) · 1.67 KB
/
run.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
55
56
57
import os
import cherrypy
from cherrypy import wsgiserver
from pecan.deploy import deploy
import prod
prod_config = os.path.abspath(os.path.join(os.path.dirname(__file__), 'prod.py'))
simpleapp_wsgi_app = deploy(prod_config)
public_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'public'))
# A dummy class for our Root object
# necessary for some CherryPy machinery
class Root(object):
pass
def make_static_config(static_dir_name):
"""
All custom static configurations are set here, since most are common, it
makes sense to generate them just once.
"""
static_path = os.path.join('/', static_dir_name)
path = os.path.join(public_path, static_dir_name)
configuration = {
static_path: {
'tools.staticdir.on': True,
'tools.staticdir.dir': path
}
}
return cherrypy.tree.mount(Root(), '/', config=configuration)
# Assuming your app has media on diferent paths, like 'css', and 'images'
application = wsgiserver.WSGIPathInfoDispatcher({
'/': simpleapp_wsgi_app,
'/css': make_static_config('css'),
'/js': make_static_config('js'),
'/images': make_static_config('images'),
'/fonts': make_static_config('fonts'),
'/favicon.ico': cherrypy.tree.mount(Root(), '/', config={
'/favicon.ico': {
'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.join(public_path, 'images', 'favicon.ico'),
},
}),
}
)
server = wsgiserver.CherryPyWSGIServer((prod.server['host'], int(prod.server['port'])), application,
server_name='simpleapp')
try:
server.start()
except KeyboardInterrupt:
print("Terminating server...")
server.stop()