forked from ceph/pulpito
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
53 lines (44 loc) · 1.46 KB
/
run.py
File metadata and controls
53 lines (44 loc) · 1.46 KB
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
import os
import cherrypy
from cheroot.wsgi import Server as WSGIServer, PathInfoDispatcher
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 = PathInfoDispatcher({
'/': 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': make_static_config('images'),
})
server = WSGIServer(
(prod.server['host'], int(prod.server['port'])),
application
)
try:
server.start()
except KeyboardInterrupt:
print("Terminating server...")
server.stop()