Skip to content

Commit 839c834

Browse files
committed
move creation of server to WSGIServer function so that it can be customized by overwriting it.
1 parent 3cdaa14 commit 839c834

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

web/httpserver.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import webapi as web
77
import net
88
import utils
9-
from wsgiserver import CherryPyWSGIServer
109

1110
def runbasic(func, server_address=("0.0.0.0", 8080)):
1211
"""
@@ -140,14 +139,21 @@ def runsimple(func, server_address=("0.0.0.0", 8080)):
140139
func = StaticMiddleware(func)
141140
func = LogMiddleware(func)
142141

143-
server = CherryPyWSGIServer(server_address, func, server_name="localhost")
142+
server = WSGIServer(server_address, func)
144143

145144
print "http://%s:%d/" % server_address
146145
try:
147146
server.start()
148147
except KeyboardInterrupt:
149148
server.stop()
150149

150+
def WSGIServer(server_address, wsgi_app):
151+
"""Creates CherryPy WSGI server listening at `server_address` to serve `wsgi_app`.
152+
This function can be overwritten to customize the webserver or use a different webserver.
153+
"""
154+
from wsgiserver import CherryPyWSGIServer
155+
return CherryPyWSGIServer(server_address, wsgi_app, server_name="localhost")
156+
151157
class StaticApp(SimpleHTTPRequestHandler):
152158
"""WSGI application for serving static files."""
153159
def __init__(self, environ, start_response):

0 commit comments

Comments
 (0)