diff index_test_server.py @ 55:0fbe37b56e84

update index_app to use _indexroot files
author paulo
date Thu, 22 Aug 2013 23:53:56 -0700
parents 50de1845520f
children
line diff
     1.1 --- a/index_test_server.py	Mon Jun 03 00:30:24 2013 -0700
     1.2 +++ b/index_test_server.py	Thu Aug 22 23:53:56 2013 -0700
     1.3 @@ -1,14 +1,38 @@
     1.4 -import wsgiref.simple_server 
     1.5 -import SocketServer
     1.6 +import os
     1.7 +import sys
     1.8 +import signal
     1.9 +
    1.10 +import cherrypy
    1.11 +from cherrypy import wsgiserver
    1.12  
    1.13  import index_app
    1.14  
    1.15  
    1.16 -class ThreadingWSGIServer(SocketServer.ThreadingMixIn, wsgiref.simple_server.WSGIServer):
    1.17 -	pass
    1.18 +def sighandler(signum, frame):
    1.19 +	sys.stderr.write("Caught signal: %s \n" % signum)
    1.20 +	server.stop()
    1.21 +
    1.22 +
    1.23 +class FileServerRoot:
    1.24 +	def default(self, *args):
    1.25 +		if len(args) == 0:
    1.26 +			raise cherrypy.HTTPError(404)
    1.27 +
    1.28 +		filepath = os.path.abspath(os.path.join(*args))
    1.29 +		return cherrypy.lib.static.serve_file(filepath)
    1.30 +
    1.31 +	default.exposed = True
    1.32  
    1.33  
    1.34  if __name__ == "__main__":
    1.35 -	httpd = ThreadingWSGIServer(('', 8000), wsgiref.simple_server.WSGIRequestHandler)
    1.36 -	httpd.set_app(index_app.app)
    1.37 -	httpd.serve_forever()
    1.38 +	fileServerApp = cherrypy.Application(FileServerRoot())
    1.39 +	dispatcher = wsgiserver.WSGIPathInfoDispatcher({
    1.40 +		"/index.fcgi": index_app.app,
    1.41 +		"": fileServerApp,
    1.42 +	})
    1.43 +	server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8000), dispatcher)
    1.44 +
    1.45 +	signal.signal(signal.SIGINT, sighandler)
    1.46 +	signal.signal(signal.SIGTERM, sighandler)
    1.47 +
    1.48 +	server.start()