1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 08:04:49 +01:00

urlrewrite: refactor simpleapp to support live/record/replay

This commit is contained in:
Ilya Kreymer 2016-04-27 10:15:48 -07:00
parent f119d05724
commit 9010e52663
3 changed files with 24 additions and 12 deletions

View File

@ -12,17 +12,17 @@ from urlrewrite.rewriterapp import RewriterApp
# ============================================================================
class RWApp(RewriterApp):
def __init__(self, upstream_url):
self.upstream_url = upstream_url
def __init__(self, upstream_urls):
self.upstream_urls = upstream_urls
self.app = Bottle()
self.block_loader = LocalFileLoader()
self.init_routes()
super(RWApp, self).__init__(True)
def get_upstream_url(self, url, wb_url, closest, kwargs):
return self.upstream_url.format(url=quote(url),
closest=closest,
type=kwargs.get('type'))
type = kwargs.get('type')
return self.upstream_urls[type].format(url=quote(url),
closest=closest)
def init_routes(self):
@self.app.get('/static/__pywb/<filepath:path>')
@ -35,12 +35,23 @@ class RWApp(RewriterApp):
return data
self.app.mount('/live/', self.call_with_params(type='live'))
self.app.mount('/replay/', self.call_with_params(type='replay-testdata'))
self.app.mount('/record/', self.call_with_params(type='record'))
self.app.mount('/replay/', self.call_with_params(type='replay'))
@staticmethod
def create_app(replay_port=8080, record_port=8010):
upstream_urls = {'live': 'http://localhost:%s/live/resource/postreq?url={url}&closest={closest}' % replay_port,
'record': 'http://localhost:%s/live/resource/postreq?url={url}&closest={closest}' % record_port,
'replay': 'http://localhost:%s/replay/resource/postreq?url={url}&closest={closest}' % replay_port,
}
rwapp = RWApp(upstream_urls)
return rwapp
# ============================================================================
if __name__ == "__main__":
rwapp = RWApp('http://localhost:8080/{type}/resource/postreq?url={url}&closest={closest}')
rwapp.app.run(port=8090)
application = RWApp.create_app()
application.app.run(port=8090, server='gevent')

View File

@ -11,10 +11,11 @@ class TestRewriter(LiveServerTests, BaseTestClass):
@classmethod
def setup_class(cls):
super(TestRewriter, cls).setup_class()
cls.upstream_url = 'http://localhost:{0}'.format(cls.server.port)
cls.upstream_url += '/{type}/resource/postreq?url={url}&closest={closest}'
#cls.upstream_url = 'http://localhost:{0}'.format(cls.server.port)
#cls.upstream_url += '/{type}/resource/postreq?url={url}&closest={closest}'
#cls.app = RWApp(cls.upstream_url)
cls.app = RWApp(cls.upstream_url)
cls.app = RWApp.create_app(replay_port=cls.server.port)
cls.testapp = webtest.TestApp(cls.app.app)
def test_replay(self):

View File

@ -13,6 +13,6 @@ endif =
gevent = 100
wsgi = testapp
wsgi = urlrewrite.test.simpleapp