Add a script for running a local dev instance of the app

(imported from commit 29813060ef17360d3a7dcc6fe1873992404457c2)
This commit is contained in:
Keegan McAllister 2012-10-09 18:16:25 -04:00
parent 1fded25025
commit 21ed4d2506
1 changed files with 47 additions and 0 deletions

47
tools/run-dev.py Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python
import subprocess
import os
from os import path
from twisted.internet import reactor
from twisted.web import proxy, server, resource
"""
Starts the app listening on localhost, for local development.
This script launches the Django and Tornado servers, then runs a reverse proxy
which serves to both of them. After it's all up and running, browse to
http://localhost:9991/
Note that, while runserver and runtornado have the usual auto-restarting
behavior, the reverse proxy itself does *not* automatically restart on changes
to this file.
"""
proxy_port = 9991
proxy_host = 'localhost:%d' % (proxy_port,)
os.chdir(path.join(path.dirname(__file__), '..'))
procs = []
for cmd in ['python manage.py runserver localhost:9992',
'python manage.py runtornado localhost:9993']:
procs.append(subprocess.Popen(cmd, shell=True))
class Resource(resource.Resource):
def getChild(self, name, request):
request.requestHeaders.setRawHeaders('X-Forwarded-Host', [proxy_host])
if request.uri in ['/get_updates', '/api/v1/get_messages']:
return proxy.ReverseProxyResource('localhost', 9993, '/'+name)
return proxy.ReverseProxyResource('localhost', 9992, '/'+name)
reactor.listenTCP(proxy_port, server.Site(Resource()), interface='127.0.0.1')
try:
reactor.run()
finally:
for proc in procs:
proc.terminate()