Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
97 lines (76 loc) · 3.04 KB
/
Copy pathmain.py
File metadata and controls
97 lines (76 loc) · 3.04 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python3
""" main.py
COMPSYS302 - Software Design - Example Client Webapp
Current Author/Maintainer: Hammond Pearce (hammond.pearce@auckland.ac.nz)
Last Edited: March 2019
This program uses the CherryPy web server (from www.cherrypy.org).
"""
# Requires: CherryPy 18.0.1 (www.cherrypy.org)
# Python (We use 3.5.x +)
import os
import cherrypy
import server
# The address we listen for connections on
#LISTEN_IP = "0.0.0.0"
LISTEN_IP = "localhost"
LISTEN_PORT = 1234
#LISTEN_PORT = 10051
def runMainApp():
#set up the config
conf = {
'/': {
'tools.staticdir.root': os.getcwd(),
'tools.encode.on': True,
'tools.encode.encoding': 'utf-8',
'tools.sessions.on': True,
'tools.sessions.timeout': 60 * 1, #timeout is in minutes, * 60 to get hours
# The default session backend is in RAM. Other options are 'file',
# 'postgres', 'memcached'. For example, uncomment:
# 'tools.sessions.storage_type': 'file',
# 'tools.sessions.storage_path': '/tmp/mysessions',
},
#configuration for the static assets directory
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': 'static',
},
#once a favicon is set up, the following code could be used to select it for cherrypy
#'/favicon.ico': {
# 'tools.staticfile.on': True,
# 'tools.staticfile.filename': os.getcwd() + '/static/favicon.ico',
#},
}
conf1 = {
'/' : {
'request.dispatch' : cherrypy.dispatch.MethodDispatcher(),
'tools.trailing_slash.on' : False
}
}
cherrypy.site = {
'base_path': os.getcwd()
}
# Create an instance of MainApp and tell Cherrypy to send all requests under / to it. (ie all of them)
cherrypy.tree.mount(server.MainApp(), "/", conf)
#
cherrypy.tree.mount(server.ApiApp(), "/api/", conf)
cherrypy.tree.mount(server.rx_broadcast(), "/api/rx_broadcast/", conf1)
cherrypy.tree.mount(server.rx_privatemessage(), "/api/rx_privatemessage/", conf1)
# Tell cherrypy where to listen, and to turn autoreload on
cherrypy.config.update({'server.socket_host': LISTEN_IP,
'server.socket_port': LISTEN_PORT,
'engine.autoreload.on': True,
'tools.sessions.timeout': 1
})
#cherrypy.tools.auth = cherrypy.Tool('before_handler', auth.check_auth, 99)
print("========================================")
print(" Hammond Pearce")
print(" University of Auckland")
print(" COMPSYS302 - Example client web app")
print("========================================")
# Start the web server
cherrypy.engine.start()
# And stop doing anything else. Let the web server take over.
cherrypy.engine.block()
#Run the function to start everything
if __name__ == '__main__':
runMainApp()