mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
Merge remote-tracking branch 'origin/master' into add-api-docs
This commit is contained in:
commit
4e7ec4dede
@ -19,7 +19,6 @@ from handlers import DebugEchoHandler, DebugEchoEnvHandler
|
|||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import yaml
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
@ -115,7 +114,12 @@ def create_wb_router(passed_config = {}):
|
|||||||
|
|
||||||
routes = []
|
routes = []
|
||||||
|
|
||||||
hostpaths = config.get('hostpaths')
|
# TODO: examine this more
|
||||||
|
hostname = os.environ.get('PYWB_HOST_NAME')
|
||||||
|
if hostname:
|
||||||
|
hostpaths = [hostname]
|
||||||
|
else:
|
||||||
|
hostpaths = config.get('hostpaths')
|
||||||
|
|
||||||
port = config.get('port')
|
port = config.get('port')
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ class J2TemplateView:
|
|||||||
jinja_env = Environment(loader = loader, trim_blocks = True)
|
jinja_env = Environment(loader = loader, trim_blocks = True)
|
||||||
jinja_env.filters['format_ts'] = J2TemplateView.format_ts
|
jinja_env.filters['format_ts'] = J2TemplateView.format_ts
|
||||||
jinja_env.filters['host'] = J2TemplateView.get_host
|
jinja_env.filters['host'] = J2TemplateView.get_host
|
||||||
|
jinja_env.filters['request_hostname'] = J2TemplateView.request_hostname
|
||||||
return jinja_env
|
return jinja_env
|
||||||
|
|
||||||
def render_to_string(self, **kwargs):
|
def render_to_string(self, **kwargs):
|
||||||
@ -65,6 +66,10 @@ class J2TemplateView:
|
|||||||
return urlparse.urlsplit(url).netloc
|
return urlparse.urlsplit(url).netloc
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def request_hostname(env):
|
||||||
|
return env.get('HTTP_HOST', 'localhost')
|
||||||
|
|
||||||
|
|
||||||
# cdx index view
|
# cdx index view
|
||||||
|
|
||||||
|
@ -37,16 +37,16 @@ class ArchivalRouter(object):
|
|||||||
if result:
|
if result:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# Home Page
|
# Default Home Page
|
||||||
if env['REL_REQUEST_URI'] in ['/', '/index.html', '/index.htm']:
|
if env['REL_REQUEST_URI'] in ['/', '/index.html', '/index.htm']:
|
||||||
return self.render_home_page()
|
return self.render_home_page(env)
|
||||||
|
|
||||||
return self.fallback(env, self.routes) if self.fallback else None
|
return self.fallback(env, self.routes) if self.fallback else None
|
||||||
|
|
||||||
def render_home_page(self):
|
def render_home_page(self, env):
|
||||||
# render the homepage!
|
# render the homepage!
|
||||||
if self.home_view:
|
if self.home_view:
|
||||||
return self.home_view.render_response(routes=self.routes)
|
return self.home_view.render_response(env=env, routes=self.routes)
|
||||||
else:
|
else:
|
||||||
# default home page template
|
# default home page template
|
||||||
text = '\n'.join(map(str, self.routes))
|
text = '\n'.join(map(str, self.routes))
|
||||||
|
@ -62,7 +62,7 @@ class ProxyRouter:
|
|||||||
request_uri=url,
|
request_uri=url,
|
||||||
wb_url_str=url,
|
wb_url_str=url,
|
||||||
#rel_prefix=url,
|
#rel_prefix=url,
|
||||||
#host_prefix=self.hostpaths[0],
|
host_prefix=self.hostpaths[0],
|
||||||
wburl_class=self.handler.get_wburl_type(),
|
wburl_class=self.handler.get_wburl_type(),
|
||||||
urlrewriter_class=ProxyHttpsUrlRewriter,
|
urlrewriter_class=ProxyHttpsUrlRewriter,
|
||||||
use_abs_prefix=False,
|
use_abs_prefix=False,
|
||||||
@ -72,7 +72,14 @@ class ProxyRouter:
|
|||||||
|
|
||||||
# Proxy Auto-Config (PAC) script for the proxy
|
# Proxy Auto-Config (PAC) script for the proxy
|
||||||
def make_pac_response(self, env):
|
def make_pac_response(self, env):
|
||||||
server_hostport = env['SERVER_NAME'] + ':' + env['SERVER_PORT']
|
import os
|
||||||
|
hostname = os.environ.get('PYWB_HOST_NAME')
|
||||||
|
if not hostname:
|
||||||
|
server_hostport = env['SERVER_NAME'] + ':' + env['SERVER_PORT']
|
||||||
|
hostonly = env['SERVER_NAME']
|
||||||
|
else:
|
||||||
|
server_hostport = hostname
|
||||||
|
hostonly = hostname.split(':')[0]
|
||||||
|
|
||||||
buff = 'function FindProxyForURL (url, host) {\n'
|
buff = 'function FindProxyForURL (url, host) {\n'
|
||||||
|
|
||||||
@ -82,7 +89,7 @@ class ProxyRouter:
|
|||||||
parts = urlparse.urlsplit(hostpath).netloc.split(':')
|
parts = urlparse.urlsplit(hostpath).netloc.split(':')
|
||||||
buff += direct.format(parts[0])
|
buff += direct.format(parts[0])
|
||||||
|
|
||||||
buff += direct.format(env['SERVER_NAME'])
|
buff += direct.format(hostonly)
|
||||||
|
|
||||||
#buff += '\n return "PROXY {0}";\n}}\n'.format(self.hostpaths[0])
|
#buff += '\n return "PROXY {0}";\n}}\n'.format(self.hostpaths[0])
|
||||||
buff += '\n return "PROXY {0}";\n}}\n'.format(server_hostport)
|
buff += '\n return "PROXY {0}";\n}}\n'.format(server_hostport)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user