Created
April 26, 2012 13:49
-
-
Save lost-theory/2499745 to your computer and use it in GitHub Desktop.
passenger WSGI stuff
This file contains 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
import sys, os | |
INTERP = "/home/username/domain/env/bin/python" | |
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv) | |
def testapp(environ, start_response): | |
import pprint | |
start_response('200 OK', [('Content-type', 'text/plain')]) | |
yield sys.version | |
yield pprint.pformat(environ) | |
############################################################################### | |
sys.path.append("/home/username/domain/env/app/") | |
from app import app | |
############################################################################### | |
#application = testapp | |
application = app |
This file contains 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
""" | |
Fakes a request to the WSGI app that passenger is using. | |
Passenger always gives an ugly 500 page with no debugging info, | |
and no info in the logs, so this is kinda the only way to debug. | |
""" | |
import os | |
from cStringIO import StringIO | |
from passenger_wsgi import application | |
DOC_ROOT = '/home/user/domain/public' | |
HOSTNAME = 'www.domain.com' | |
def start_response(*args, **kwargs): | |
print args, kwargs | |
def go(url='/', method='GET'): | |
io = StringIO() | |
environ = { | |
'SCRIPT_NAME': '', | |
'SERVER_PROTOCOL': 'HTTP/1.1', | |
'HTTP_USER_AGENT': 'Mozilla/5.0 Gecko/20100101 Firefox/4.0', | |
'HTTP_CONNECTION': 'keep-alive', | |
'REMOTE_ADDR': '127.0.0.1', | |
'wsgi.url_scheme': 'http', | |
'SERVER_PORT': '80', | |
'SERVER_ADDR': '127.0.0.1', | |
'wsgi.multiprocess': False, | |
'DOCUMENT_ROOT': DOC_ROOT, | |
'SERVER_NAME': HOSTNAME, | |
'HTTP_HOST': HOSTNAME, | |
'wsgi.multithread': False, | |
'wsgi.run_once': True, | |
'wsgi.input': io, | |
'SCRIPT_URI': 'http://%s%s' % (HOSTNAME, url), | |
'REQUEST_URI': url, | |
'PATH_INFO': url, | |
'SCRIPT_URL': url, | |
'REQUEST_METHOD': method, | |
'QUERY_STRING': '', | |
} | |
os.environ = environ | |
res = application(environ, start_response) | |
return list(res) | |
if __name__ == "__main__": | |
import sys | |
arg = sys.argv.pop() | |
if arg.startswith('/'): | |
print go(arg) | |
else: | |
import code; code.interact(local=locals()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment