annotate index_test_server.py @ 144:90f3021e3137

myrss2: FEEDS: Remove longform.org; add propublic.org
author paulo
date Tue, 28 May 2024 06:23:58 +0000
parents 50de1845520f
children
rev   line source
paulo@55 1 import os
paulo@55 2 import sys
paulo@55 3 import signal
paulo@55 4
paulo@55 5 import cherrypy
paulo@55 6 from cherrypy import wsgiserver
paulo@48 7
paulo@48 8 import index_app
paulo@48 9
paulo@48 10
paulo@55 11 def sighandler(signum, frame):
paulo@55 12 sys.stderr.write("Caught signal: %s \n" % signum)
paulo@55 13 server.stop()
paulo@55 14
paulo@55 15
paulo@55 16 class FileServerRoot:
paulo@55 17 def default(self, *args):
paulo@55 18 if len(args) == 0:
paulo@55 19 raise cherrypy.HTTPError(404)
paulo@55 20
paulo@55 21 filepath = os.path.abspath(os.path.join(*args))
paulo@55 22 return cherrypy.lib.static.serve_file(filepath)
paulo@55 23
paulo@55 24 default.exposed = True
paulo@48 25
paulo@48 26
paulo@48 27 if __name__ == "__main__":
paulo@55 28 fileServerApp = cherrypy.Application(FileServerRoot())
paulo@55 29 dispatcher = wsgiserver.WSGIPathInfoDispatcher({
paulo@55 30 "/index.fcgi": index_app.app,
paulo@55 31 "": fileServerApp,
paulo@55 32 })
paulo@55 33 server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8000), dispatcher)
paulo@55 34
paulo@55 35 signal.signal(signal.SIGINT, sighandler)
paulo@55 36 signal.signal(signal.SIGTERM, sighandler)
paulo@55 37
paulo@55 38 server.start()