mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
non-root deployment and static prefix: (ported from uk-pywb fork) (#373)
- store original wsgi SCRIPT_NAME (before collection path is pushed) in 'pywb.app_prefix' env var - set 'pywb.host_prefix' via rewriterapp - add 'static_prefix' jinja env global which defaults to 'pywb.host_prefix + pywb.app_prefix + static/' - set 'static_prefix' to absolute url if available (to support proxy mode) - update existing templates to use '{{ static_prefix }}' instead of '{{ host_prefix }}/{{ static_path }' - update index.html to use pywb.app_prefix for collection links - tests: add test_prefixed_deploy.py to ensure all paths are prefixed as expected
This commit is contained in:
parent
6a2423e754
commit
0bf2e08b27
@ -357,6 +357,9 @@ class FrontEndApp(object):
|
||||
try:
|
||||
endpoint, args = urls.match()
|
||||
|
||||
# store original script_name (original prefix) before modifications are made
|
||||
environ['pywb.app_prefix'] = environ.get('SCRIPT_NAME')
|
||||
|
||||
response = endpoint(environ, **args)
|
||||
return response(environ, start_response)
|
||||
|
||||
|
@ -256,6 +256,8 @@ class RewriterApp(object):
|
||||
|
||||
urlkey = canonicalize(wb_url.url)
|
||||
|
||||
environ['pywb.host_prefix'] = host_prefix
|
||||
|
||||
if self.use_js_obj_proxy:
|
||||
content_rw = self.js_proxy_rw
|
||||
else:
|
||||
|
@ -139,7 +139,10 @@ class BaseInsertView(object):
|
||||
params = env.get(self.jenv.env_template_params_key)
|
||||
if params:
|
||||
kwargs.update(params)
|
||||
|
||||
kwargs['env'] = env
|
||||
kwargs['static_prefix'] = env.get('pywb.host_prefix', '') + env.get('pywb.app_prefix', '') + '/static'
|
||||
|
||||
|
||||
return template.render(**kwargs)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
{% if not env.pywb_proxy_magic or config.proxy.use_banner | default(true) %}
|
||||
<!-- default banner, create through js -->
|
||||
<script src='{{ host_prefix }}/{{ static_path }}/default_banner.js'> </script>
|
||||
<link rel='stylesheet' href='{{ host_prefix }}/{{ static_path }}/default_banner.css'/>
|
||||
<script src='{{ static_prefix }}/default_banner.js'> </script>
|
||||
<link rel='stylesheet' href='{{ static_prefix }}/default_banner.css'/>
|
||||
{% endif %}
|
||||
|
@ -12,7 +12,7 @@ html, body
|
||||
}
|
||||
|
||||
</style>
|
||||
<script src='{{ host_prefix }}/{{ static_path }}/wb_frame.js'> </script>
|
||||
<script src='{{ static_prefix }}/wb_frame.js'> </script>
|
||||
|
||||
{{ banner_html }}
|
||||
|
||||
|
@ -23,11 +23,11 @@
|
||||
wbinfo.is_live = {{ is_live }};
|
||||
wbinfo.coll = "{{ coll }}";
|
||||
wbinfo.proxy_magic = "{{ env.pywb_proxy_magic }}";
|
||||
wbinfo.static_prefix = "{{ host_prefix }}/{{ static_path }}/";
|
||||
wbinfo.static_prefix = "{{ static_prefix }}/";
|
||||
</script>
|
||||
|
||||
{% if not wb_url.is_banner_only %}
|
||||
<script src='{{ host_prefix }}/{{ static_path }}/wombat.js'> </script>
|
||||
<script src='{{ static_prefix }}/wombat.js'> </script>
|
||||
<script>
|
||||
wbinfo.wombat_ts = "{{ wombat_ts }}";
|
||||
wbinfo.wombat_sec = "{{ wombat_sec }}";
|
||||
@ -49,7 +49,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if config.enable_flash_video_rewrite %}
|
||||
<script src='{{ host_prefix }}/{{ static_path }}/vidrw.js'> </script>
|
||||
<script src='{{ static_prefix }}/vidrw.js'> </script>
|
||||
{% endif %}
|
||||
|
||||
{{ banner_html }}
|
||||
|
@ -8,7 +8,7 @@ This archive contains the following collections:
|
||||
<ul>
|
||||
{% for route in routes %}
|
||||
<li>
|
||||
<a href="{{ '/' + route }}">{{ '/' + route }}</a>
|
||||
<a href="{{ env['pywb.app_prefix'] + '/' + route }}">{{ '/' + route }}</a>
|
||||
{% if all_metadata and all_metadata[route] %}
|
||||
({{ all_metadata[route].title }})
|
||||
{% endif %}
|
||||
|
@ -1,12 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- jquery and bootstrap dependencies query view -->
|
||||
<link rel="stylesheet" href="{{ host_prefix }}/{{ static_path }}/css/query.css">
|
||||
<link rel="stylesheet" href="{{ host_prefix }}/{{ static_path }}/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="{{ host_prefix }}/{{ static_path }}/css/font-awesome.min.css">
|
||||
<script src="{{ host_prefix }}/{{ static_path }}/js/jquery-latest.min.js"></script>
|
||||
<script src="{{ host_prefix }}/{{ static_path }}/js/bootstrap.min.js"></script>
|
||||
<script src="{{ host_prefix }}/{{ static_path }}/query.js"></script>
|
||||
<link rel="stylesheet" href="{{ static_prefix }}/css/query.css">
|
||||
<link rel="stylesheet" href="{{ static_prefix }}/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="{{ static_prefix }}/css/font-awesome.min.css">
|
||||
<script src="{{ static_prefix }}/js/jquery-latest.min.js"></script>
|
||||
<script src="{{ static_prefix }}/js/bootstrap.min.js"></script>
|
||||
<script src="{{ static_prefix }}/query.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h2 class="text-center">pywb Query Results</h2>
|
||||
|
50
tests/test_prefixed_deploy.py
Normal file
50
tests/test_prefixed_deploy.py
Normal file
@ -0,0 +1,50 @@
|
||||
from .base_config_test import BaseConfigTest, fmod
|
||||
|
||||
|
||||
# ============================================================================
|
||||
class TestPrefixedDeploy(BaseConfigTest):
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
super(TestPrefixedDeploy, cls).setup_class('config_test.yaml')
|
||||
|
||||
def get(self, url, fmod=''):
|
||||
return super(TestPrefixedDeploy, self).get(url, fmod,
|
||||
extra_environ={'SCRIPT_NAME': '/prefix',
|
||||
'REQUEST_URI': 'http://localhost:80/prefix' + url})
|
||||
|
||||
def test_home(self):
|
||||
resp = self.get('/prefix/')
|
||||
print(resp.text)
|
||||
self._assert_basic_html(resp)
|
||||
assert '/prefix/pywb' in resp.text
|
||||
|
||||
def test_pywb_root(self):
|
||||
resp = self.get('/prefix/pywb/')
|
||||
self._assert_basic_html(resp)
|
||||
assert 'Search' in resp.text
|
||||
|
||||
def test_calendar_query(self):
|
||||
resp = self.get('/prefix/pywb/*/iana.org')
|
||||
self._assert_basic_html(resp)
|
||||
|
||||
assert '/prefix/static/query.js' in resp.text
|
||||
|
||||
def test_replay_content(self, fmod):
|
||||
resp = self.get('/prefix/pywb/20140127171238{0}/http://www.iana.org/', fmod)
|
||||
self._assert_basic_html(resp)
|
||||
|
||||
assert '"20140127171238"' in resp.text, resp.text
|
||||
assert "'http://localhost:80/prefix/static/wombat.js'" in resp.text
|
||||
assert "'http://localhost:80/prefix/static/default_banner.js'" in resp.text
|
||||
assert '"http://localhost:80/prefix/static/"' in resp.text
|
||||
assert '"http://localhost:80/prefix/pywb/"' in resp.text
|
||||
assert 'new _WBWombat' in resp.text, resp.text
|
||||
assert '"/prefix/pywb/20140127171238{0}/http://www.iana.org/time-zones"'.format(fmod) in resp.text, resp.text
|
||||
|
||||
def test_static_content(self):
|
||||
resp = self.get('/prefix/static/default_banner.css')
|
||||
assert resp.status_int == 200
|
||||
assert resp.content_type == 'text/css'
|
||||
assert resp.content_length > 0
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user