I learned about SCRIPT_NAME

This commit is contained in:
iou1name 2018-07-31 17:12:15 -04:00
parent 1abf8eb8e1
commit c9e9250815
3 changed files with 4 additions and 45 deletions

View File

@ -18,7 +18,7 @@ mysql> \q
2. Walk the dinosaur
## Usage
`gunicorn -b localhost:5050 --worker-class eventlet anonkun:app`
`gunicorn -b localhost:5050 -e SCRIPT_NAME=/anonkun --worker-class eventlet anonkun:app`
## Todo
Rename this project to something that doesn't mean "shit" in weebspeak.

View File

@ -16,43 +16,7 @@ import database as db
from views import views
from events import socketio
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', '')
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.wsgi_app = ProxyFix(app.wsgi_app)
app.register_blueprint(views)
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024

View File

@ -40,14 +40,9 @@
{% if quest_post[3] == "text" %}
<br /><a href="javascript:void(0);" id="editPost-{{ quest_post[0] }}" onclick="edit_post({{ quest_post[0] }})">Edit</a>
<a href="javascript:void(0);" id="savePost-{{ quest_post[0] }}" onclick="save_post('{{ quest_post[0] }}')" style="display:none;">Save</a>
{% elif quest_post[3] == "dice" or quest_post[3] == "poll" and quest_post == quest_posts|last %}
{% if quest_post[0] == open_post_id %}
<br /><a href="javascript:void(0);" id="close_post_id-{{ quest_post[0] }}" onclick="close_post({{ quest_post[0] }})">Close</a>
<a href="javascript:void(0);" id="open_post_id-{{ quest_post[0] }}" onclick="open_post({{ quest_post[0] }})" style="display:none;">Open</a>
{% else %}
<br /><a href="javascript:void(0);" id="close_post_id-{{ quest_post[0] }}" onclick="close_post({{ quest_post[0] }})" style="display:none;">Close</a>
<a href="javascript:void(0);" id="open_post_id-{{ quest_post[0] }}" onclick="open_post({{ quest_post[0] }})">Open</a>
{% endif %}
{% elif (quest_post[3] == "dice" or quest_post[3] == "poll") and quest_post == quest_posts|last %}
<br /><a href="javascript:void(0);" id="close_post_id-{{ quest_post[0] }}" onclick="close_post({{ quest_post[0] }})"{% if quest_post[0] != open_post_id %} style="display:none;"{% endif %}>Close</a>
<a href="javascript:void(0);" id="open_post_id-{{ quest_post[0] }}" onclick="open_post({{ quest_post[0] }})"{% if quest_post[0] == open_post_id %} style="display:none;"{% endif %}>Open</a>
{% endif %}
{% endif %}
</div>