annotate laterlinks2/test_server.py @ 91:6a45e46f0c05

myw: use new redirect_app
author paulo
date Thu, 06 Apr 2017 22:42:03 -0700
parents
children
rev   line source
paulo@60 1 import os
paulo@60 2 import sys
paulo@60 3 import signal
paulo@60 4
paulo@60 5 import cherrypy
paulo@60 6 from cherrypy import wsgiserver
paulo@60 7
paulo@60 8 import laterlinks_app
paulo@60 9
paulo@60 10
paulo@60 11 def sighandler(signum, frame):
paulo@60 12 sys.stderr.write("Caught signal: %s \n" % signum)
paulo@60 13 server.stop()
paulo@60 14
paulo@60 15
paulo@60 16 class FileServerRoot:
paulo@60 17 def default(self, *args):
paulo@60 18 if len(args) == 0:
paulo@60 19 raise cherrypy.HTTPError(404)
paulo@60 20
paulo@60 21 filepath = os.path.abspath(os.path.join(*args))
paulo@60 22 return cherrypy.lib.static.serve_file(filepath)
paulo@60 23
paulo@60 24 default.exposed = True
paulo@60 25
paulo@60 26
paulo@60 27 if __name__ == "__main__":
paulo@60 28 fileServerApp = cherrypy.Application(FileServerRoot())
paulo@60 29 dispatcher = wsgiserver.WSGIPathInfoDispatcher({
paulo@60 30 "/index.fcgi": laterlinks_app.app,
paulo@60 31 "": fileServerApp,
paulo@60 32 })
paulo@60 33 server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8000), dispatcher)
paulo@60 34
paulo@60 35 signal.signal(signal.SIGINT, sighandler)
paulo@60 36 signal.signal(signal.SIGTERM, sighandler)
paulo@60 37
paulo@60 38 server.start()