From 1a18eec12d2d27958eae22710ce3829ad3d3b06f Mon Sep 17 00:00:00 2001 From: "Walter, Mathias" Date: Tue, 26 Feb 2013 16:40:55 +0100 Subject: [PATCH 1/3] added url_for to src of the css, fonts and javascripts - for #33 --- static/css/editor.css | 2 +- static/css/fonts.css | 10 +++++----- templates/base.html | 42 +++++++++++++++++++++--------------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/static/css/editor.css b/static/css/editor.css index 3df60fe0..7eb6c83f 100644 --- a/static/css/editor.css +++ b/static/css/editor.css @@ -70,7 +70,7 @@ body } .wmd-button > span { - background-image: url("/static/img/wmd-buttons.png"); + background-image: url_for('static', filename='img/wmd-buttons.png'); background-repeat: no-repeat; background-position: 0px 0px; width: 20px; diff --git a/static/css/fonts.css b/static/css/fonts.css index fdd7bcf5..e9b5a272 100644 --- a/static/css/fonts.css +++ b/static/css/fonts.css @@ -1,10 +1,10 @@ @font-face { font-family: 'icomoon'; - src:url('/static/fonts/icomoon.eot'); - src:url('/static/fonts/icomoon.eot?#iefix') format('embedded-opentype'), - url('/static/fonts/icomoon.woff') format('woff'), - url('/static/fonts/icomoon.ttf') format('truetype'), - url('/static/fonts/icomoon.svg#icomoon') format('svg'); + src:url_for('static', filename='fonts/icomoon.eot'); + src:url_for('static', filename='fonts/icomoon.eot', _anchor='iefix') format('embedded-opentype'), + url_for('static', filename='fonts/icomoon.woff') format('woff'), + url_for('static', filename='fonts/icomoon.ttf') format('truetype'), + url_for('static', filename='fonts/icomoon.svg#icomoon') format('svg'); font-weight: normal; font-style: normal; } diff --git a/templates/base.html b/templates/base.html index 988f0c60..cd9ecdd7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,20 +7,20 @@ - + - - - - - - + + + + + + - - + + - - - - - - - - - - - - + + + + + + + + + + + {% block head %} {% endblock head %} From 32e7427e45c4b281a0a4a393f07fa98e2701d086 Mon Sep 17 00:00:00 2001 From: "Walter, Mathias" Date: Wed, 27 Feb 2013 17:09:38 +0100 Subject: [PATCH 2/3] fixing SCRIPT_NAME/url_scheme when behind reverse proxy --- server.py | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index 3d484e63..8202f40a 100644 --- a/server.py +++ b/server.py @@ -27,9 +27,49 @@ PANDOC_EXTENSIONS = ['pdf', 'docx', 'epub', 'html'] DOCVERTER_URL = 'http://c.docverter.com/convert' PDFLATEX_EXISTS = distutils.spawn.find_executable("pdflatex") != None -STATIC_URL_PATH = '/markx/static' # flask default -app = Flask(__name__, static_url_path=STATIC_URL_PATH) +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:5000; + 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; + } + + In Apache2: + + ProxyPass http://192.168.0.1:5000 + ProxyPassReverse http://192.168.0.1:5000 + RequestHeader set X-Script-Name /markx + + + :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', '') + 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) + +app = Flask(__name__) +app.wsgi_app = ReverseProxied(app.wsgi_app) app.config.from_object(__name__) print " * Overriding deafult configuration with config.py file" app.config.from_pyfile('config.py', silent=True) From 1d5a0775858aa5d1866b4ab7a2820cea9033178e Mon Sep 17 00:00:00 2001 From: "Walter, Mathias" Date: Thu, 28 Feb 2013 01:02:50 +0100 Subject: [PATCH 3/3] fixes #33: how to run in suburl instead of root --- server.py | 9 +++++++-- static/css/editor.css | 2 +- static/css/fonts.css | 10 +++++----- templates/base.html | 42 +++++++++++++++++++++--------------------- templates/index.html | 4 ++-- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/server.py b/server.py index 8202f40a..dd54066b 100644 --- a/server.py +++ b/server.py @@ -3,7 +3,7 @@ reload(sys) sys.setdefaultencoding('utf-8') -from flask import Flask, request, render_template, jsonify, Response, send_file +from flask import Flask, request, render_template, url_for, jsonify, Response, send_file import os import os.path import subprocess @@ -28,6 +28,8 @@ DOCVERTER_URL = 'http://c.docverter.com/convert' PDFLATEX_EXISTS = distutils.spawn.find_executable("pdflatex") != None +app = Flask(__name__) + class ReverseProxied(object): '''Wrap the application in this middleware and configure the front-end server to add these headers, to let you quietly bind @@ -68,8 +70,11 @@ def __call__(self, environ, start_response): environ['wsgi.url_scheme'] = scheme return self.app(environ, start_response) -app = Flask(__name__) app.wsgi_app = ReverseProxied(app.wsgi_app) +def get_url_for(filename, **values): + return url_for('static', filename=filename, **values) +app.jinja_env.globals['static'] = get_url_for + app.config.from_object(__name__) print " * Overriding deafult configuration with config.py file" app.config.from_pyfile('config.py', silent=True) diff --git a/static/css/editor.css b/static/css/editor.css index 7eb6c83f..a7432527 100644 --- a/static/css/editor.css +++ b/static/css/editor.css @@ -70,7 +70,7 @@ body } .wmd-button > span { - background-image: url_for('static', filename='img/wmd-buttons.png'); + background-image: url('../img/wmd-buttons.png'); background-repeat: no-repeat; background-position: 0px 0px; width: 20px; diff --git a/static/css/fonts.css b/static/css/fonts.css index e9b5a272..88c5c9ca 100644 --- a/static/css/fonts.css +++ b/static/css/fonts.css @@ -1,10 +1,10 @@ @font-face { font-family: 'icomoon'; - src:url_for('static', filename='fonts/icomoon.eot'); - src:url_for('static', filename='fonts/icomoon.eot', _anchor='iefix') format('embedded-opentype'), - url_for('static', filename='fonts/icomoon.woff') format('woff'), - url_for('static', filename='fonts/icomoon.ttf') format('truetype'), - url_for('static', filename='fonts/icomoon.svg#icomoon') format('svg'); + src:url('../fonts/icomoon.eot'); + src:url('../fonts/icomoon.eot?#iefix') format('embedded-opentype'), + url('../fonts/icomoon.woff') format('woff'), + url('../fonts/icomoon.ttf') format('truetype'), + url('../fonts/icomoon.svg#icomoon') format('svg'); font-weight: normal; font-style: normal; } diff --git a/templates/base.html b/templates/base.html index cd9ecdd7..e8a03bc1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,20 +7,20 @@ - + - - - - - - + + + + + + - - + + - - - - - - - - - - - - + + + + + + + + + + + {% block head %} {% endblock head %} diff --git a/templates/index.html b/templates/index.html index 92d1442d..ec4e3ee5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,7 +5,7 @@
- +