summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryvesf <yvesf@pinky.(none)>2010-11-24 22:41:28 +0100
committeryvesf <yvesf@pinky.(none)>2010-11-24 22:41:28 +0100
commitff87c6dcaa65c3b1ac366a0ce05b9d6ecf7445b6 (patch)
tree8dbd16b11546bf4a6a940b7c5f0a79d94dad48c9
parent9a1362c62fb52c125fd818a147e63c96c317081f (diff)
downloadbooksearch-ff87c6dcaa65c3b1ac366a0ce05b9d6ecf7445b6.tar.gz
booksearch-ff87c6dcaa65c3b1ac366a0ce05b9d6ecf7445b6.zip
proxy fixups
-rw-r--r--templates/_base.html2
-rw-r--r--templates/search.html6
-rw-r--r--web.py4
-rw-r--r--web_proxy.py40
4 files changed, 46 insertions, 6 deletions
diff --git a/templates/_base.html b/templates/_base.html
index c62cedb..02c1ebc 100644
--- a/templates/_base.html
+++ b/templates/_base.html
@@ -10,7 +10,7 @@
<script>
function start() {
var inputField = document.getElementById("searchInput");
- window.location = "/search/" + inputField.value;
+ window.location = "{{ url_for("do_search") }}" + inputField.value;
return false;
}
</script>
diff --git a/templates/search.html b/templates/search.html
index 490cf75..dc4cfe8 100644
--- a/templates/search.html
+++ b/templates/search.html
@@ -13,7 +13,7 @@
var docnum = ui.newContent.find("p.docnum").text();
var term = ui.newContent.find("p.term").text();
/* load excerpt */
- jQuery.get('/excerpt/' + docnum + '/' + term,
+ jQuery.get("{{ url_for("do_excerpt", docnum=-9999, term="TERM") }}".replace("-9999", docnum).replace("TERM", term),
function(data) {
ui.newContent.children("div.excerpt").html(data);
}
@@ -21,9 +21,9 @@
/* update image preview */
var frontpage = jQuery(this).parent().parent().find("img.frontpage");
- frontpage.attr('src', '/static/ajax-loader.gif');
+ frontpage.attr('src', "{{ url_for("static", filename="ajax-loader.gif") }}");
frontpage.load(function() {
- frontpage.attr('src', '/page/image/' + docnum);
+ frontpage.attr('src', "{{ url_for("do_page_image",docnum=-9999) }}".replace("-9999", docnum));
});
/* scroll image preview */
diff --git a/web.py b/web.py
index 23a69bd..0ae73bb 100644
--- a/web.py
+++ b/web.py
@@ -101,7 +101,7 @@ class MyHtmlFormatter(highlight.HtmlFormatter):
return highlight.HtmlFormatter._format_fragment(self, text, fragment, seen)
@app.route("/excerpt/<int:docnum>/<path:term>", methods=["GET"])
-def excerpt(docnum, term):
+def do_excerpt(docnum, term):
def generator(q):
for result in searcher.search(q, limit=1, sortedby="pagenumber"):
terms = [ text for fieldname, text in q.all_terms()
@@ -168,4 +168,4 @@ def log_response(sender, response):
'Response: %s', response)
if __name__ == "__main__":
app.debug = True
- app.run(host="0.0.0.0")
+ app.run(host="0.0.0.0", port=8000)
diff --git a/web_proxy.py b/web_proxy.py
new file mode 100644
index 0000000..ec5fd55
--- /dev/null
+++ b/web_proxy.py
@@ -0,0 +1,40 @@
+class ReverseProxied(object):
+ '''Wrap the application in this middleware and configure the
+ front-end server to add these headers, to let you quietly bind
+ this to a URL other than / and to an HTTP scheme that is
+ different than what is used locally.
+
+ In nginx:
+ location /myprefix {
+ proxy_pass http://192.168.0.1:5001;
+ proxy_set_header Host $host;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Scheme $scheme;
+ proxy_set_header X-Script-Name /myprefix;
+ }
+
+ :param app: the WSGI application
+ '''
+ def __init__(self, app):
+ self.app = app
+
+ def __call__(self, environ, start_response):
+ script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
+ #XXXX
+ script_name = "/booksearch"
+ if script_name:
+ environ['SCRIPT_NAME'] = script_name
+ path_info = environ['PATH_INFO']
+ if path_info.startswith(script_name):
+ environ['PATH_INFO'] = path_info[len(script_name):]
+
+ scheme = environ.get('HTTP_X_SCHEME', '')
+ if scheme:
+ environ['wsgi.url_scheme'] = scheme
+ return self.app(environ, start_response)
+
+from web import app
+if __name__ == "__main__":
+ app.debug = True
+ app.wsgi_app = ReverseProxied(app.wsgi_app)
+ app.run(host="0.0.0.0", port=8000)