Shift __main__'s wsgi code where it belongs
parent
d9f46b23a6
commit
2fc7cd391c
|
@ -25,36 +25,15 @@ from . import cli
|
|||
|
||||
from .morss import MorssException
|
||||
|
||||
import wsgiref.simple_server
|
||||
import wsgiref.handlers
|
||||
|
||||
|
||||
PORT = int(os.getenv('PORT', 8080))
|
||||
|
||||
|
||||
def main():
|
||||
if 'REQUEST_URI' in os.environ:
|
||||
# mod_cgi (w/o file handler)
|
||||
|
||||
app = wsgi.cgi_app
|
||||
app = wsgi.cgi_dispatcher(app)
|
||||
app = wsgi.cgi_error_handler(app)
|
||||
app = wsgi.cgi_encode(app)
|
||||
|
||||
wsgiref.handlers.CGIHandler().run(app)
|
||||
wsgi.cgi_handle_request()
|
||||
|
||||
elif len(sys.argv) <= 1:
|
||||
# start internal (basic) http server (w/ file handler)
|
||||
|
||||
app = wsgi.cgi_app
|
||||
app = wsgi.cgi_file_handler(app)
|
||||
app = wsgi.cgi_dispatcher(app)
|
||||
app = wsgi.cgi_error_handler(app)
|
||||
app = wsgi.cgi_encode(app)
|
||||
|
||||
print('Serving http://localhost:%s/' % PORT)
|
||||
httpd = wsgiref.simple_server.make_server('', PORT, app)
|
||||
httpd.serve_forever()
|
||||
wsgi.cgi_start_server()
|
||||
|
||||
else:
|
||||
# as a CLI app
|
||||
|
|
|
@ -22,6 +22,8 @@ import lxml.etree
|
|||
|
||||
import cgitb
|
||||
import wsgiref.util
|
||||
import wsgiref.simple_server
|
||||
import wsgiref.handlers
|
||||
import mimetypes
|
||||
|
||||
try:
|
||||
|
@ -37,6 +39,9 @@ from .morss import FeedFetch, FeedGather, FeedFormat
|
|||
from .morss import Options, log, TIMEOUT, DELAY, MorssException
|
||||
|
||||
|
||||
PORT = int(os.getenv('PORT', 8080))
|
||||
|
||||
|
||||
def parse_options(options):
|
||||
""" Turns ['md=True'] into {'md':True} """
|
||||
out = {}
|
||||
|
@ -267,3 +272,18 @@ application = cgi_file_handler(application)
|
|||
application = cgi_dispatcher(application)
|
||||
application = cgi_error_handler(application)
|
||||
application = cgi_encode(application)
|
||||
|
||||
|
||||
def cgi_handle_request():
|
||||
app = cgi_app
|
||||
app = cgi_dispatcher(app)
|
||||
app = cgi_error_handler(app)
|
||||
app = cgi_encode(app)
|
||||
|
||||
wsgiref.handlers.CGIHandler().run(app)
|
||||
|
||||
|
||||
def cgi_start_server():
|
||||
print('Serving http://localhost:%s/' % PORT)
|
||||
httpd = wsgiref.simple_server.make_server('', PORT, application)
|
||||
httpd.serve_forever()
|
||||
|
|
Loading…
Reference in New Issue