def create_perma_wb_router(config={}): """ Configure server. This should do basically the same stuff as pywb.webapp.pywb_init.create_wb_router() """ # start with the default PyWB router router = create_wb_router(config) # insert a custom route that knows how to play back based on GUID wb_handler = create_wb_handler( QueryHandler.init_from_config(PermaCDXSource()), dict( archive_paths=[get_archive_path()], wb_handler_class=PermaGUIDHandler, buffer_response=True, # head_insert_html=os.path.join(os.path.dirname(__file__), 'head_insert.html'), enable_memento=True, redir_to_exact=False)) wb_handler.replay.content_loader.record_loader.loader = CachedLoader() route = PermaRoute(GUID_REGEX, wb_handler) router.routes.insert(0, route) # use our Django error view router.error_view = PermaTemplateView('archive/archive-error.html') wb_handler.not_found_view = router.error_view return router
def create_perma_wb_router(config={}): """ Configure server. This should do basically the same stuff as pywb.webapp.pywb_init.create_wb_router() """ # start with the default PyWB router router = create_wb_router(config) # insert a custom route that knows how to play back based on GUID wb_handler = create_wb_handler(QueryHandler.init_from_config(PermaCDXSource()), dict(archive_paths=[get_archive_path()], wb_handler_class=PermaGUIDHandler, buffer_response=True, # head_insert_html=os.path.join(os.path.dirname(__file__), 'head_insert.html'), enable_memento=True, redir_to_exact=False)) wb_handler.replay.content_loader.record_loader.loader = CachedLoader() route = PermaRoute(GUID_REGEX, wb_handler) router.routes.insert(0, route) # use our Django error view router.error_view = PermaTemplateView('archive/archive-error.html') wb_handler.not_found_view = router.error_view return router
def __init__(self, app): self.pywb = create_wb_router(app.webrec.config) self.manager = app.webrec.manager self.path_parser = app.webrec.path_parser self.app = app proxy_path = expandvars(app.webrec.config['proxy_path']) self.warcprox_proxies = {'http': proxy_path, 'https': proxy_path} self.init_early_routes()
def create_perma_wb_router(config={}): """ Configure server. This should do basically the same stuff as pywb.webapp.pywb_init.create_wb_router() """ # paths script_path = os.path.dirname(__file__) # Get root storage location for warcs. # archive_path should be the location pywb can find warcs, like 'file://generated/' or 'http://perma.s3.amazonaws.com/generated/' # We can get it by requesting the location of a blank file from default_storage. # default_storage may use disk or network storage depending on config, so we look for either a path() or url() try: archive_path = 'file://' + default_storage.path('') + '/' except NotImplementedError: archive_path = default_storage.url('/') archive_path = archive_path.split('?', 1)[0] # remove query params query_handler = QueryHandler.init_from_config(PermaCDXSource()) # pywb template vars (used in templates called by pywb, such as head_insert.html, but not our ErrorTemplateView) add_env_globals({'static_path': settings.STATIC_URL}) # use util func to create the handler wb_handler = create_wb_handler( query_handler, dict(archive_paths=[archive_path], wb_handler_class=PermaGUIDHandler, buffer_response=True, head_insert_html=os.path.join(script_path, 'head_insert.html'), enable_memento=True, redir_to_exact=False)) wb_handler.replay.content_loader.record_loader.loader = CachedLoader() route = PermaRoute(GUID_REGEX, wb_handler) router = create_wb_router(config) router.error_view = PermaTemplateView('archive-error.html') router.routes.insert(0, route) return router