-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
102 lines (79 loc) · 3.26 KB
/
main.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
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
98
99
100
101
102
#!/usr/bin/python3
""" main.py
COMPSYS302 - Software Design - Example Client Webapp
Current Author/Maintainer: Hammond Pearce ([email protected])
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
import socket
# The address we listen for connections on
ip = socket.gethostbyname(socket.gethostname())
print(ip)
#LISTEN_IP = "10.104.131.205"
LISTEN_IP = "" + ip+ ""
LISTEN_PORT = 10050
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',
},
# '/api': {
# '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',
},
}
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)
# 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,
})
#cherrypy.tools.auth = cherrypy.Tool('before_handler', auth.check_auth, 99)
print("========================================")
print(" Suraj Kumars")
print(" University of Auckland")
print(" COMPSYS302 - 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()