Last active
March 31, 2017 08:43
-
-
Save defanator/3f746ed9ceeb860d21363219f6e83a67 to your computer and use it in GitHub Desktop.
Test WSGI application useful for debugging purposes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[uwsgi] | |
uid=nginx | |
gid=nginx | |
socket = 0.0.0.0:3131 | |
max-requests = 4000 | |
buffer-size = 16384 | |
master = true | |
log-master = true | |
die-on-term = true | |
vacuum = true | |
file = /data/testapp/testapp.py | |
pidfile = /data/testapp/testapp.pid | |
master-fifo = /data/testapp/testapp-fifo | |
logto = /data/testapp/testapp-uwsgi.log | |
workers = 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# ./nginman --listen 9999 --py-path `pwd` --py-module testapp | |
def application(environ, start_response): | |
response_body = "ENVIRON:\n\n" + "\n".join(["{0}: {1}".format(k, environ[k]) for k in sorted(environ.keys())]) | |
body = '' | |
try: | |
length = int(environ.get('CONTENT_LENGTH', '0')) | |
except ValueError: | |
length = 0 | |
if length != 0: | |
body = environ['wsgi.input'].read(length) | |
response_body = response_body + "\n\nBODY:\n\n" | |
response_body = response_body + body | |
status = '200 OK' | |
response_headers = [('Content-Type', 'text/plain'), | |
('Content-Length', str(len(response_body)))] | |
start_response(status, response_headers) | |
return [response_body] | |
if __name__ == '__main__': | |
try: | |
from wsgiref.simple_server import make_server | |
httpd = make_server('', 8080, application) | |
print('Serving on port 8080...') | |
httpd.serve_forever() | |
except KeyboardInterrupt: | |
print('Goodbye.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment