From c364901df2ef04553fc7508c31446ad14ac93737 Mon Sep 17 00:00:00 2001 From: B Stack Date: Mon, 14 Feb 2022 22:49:17 -0500 Subject: r-proxy support with /set endpoint, and extra dir The extra dir is still WIP --- stackbin.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'stackbin.py') diff --git a/stackbin.py b/stackbin.py index bcfd3d5..e8948fd 100755 --- a/stackbin.py +++ b/stackbin.py @@ -5,6 +5,7 @@ from datetime import datetime, timedelta from itsdangerous import Signer from flask import (Flask, request, url_for, redirect, g, render_template, session, abort) from flask_sqlalchemy import SQLAlchemy +from werkzeug.middleware.proxy_fix import ProxyFix from pytimeparse.timeparse import timeparse # python3-pytimeparse # uwsgidecorators load will fail when using initdb.py but is also not necessary try: @@ -283,5 +284,13 @@ def favicon(): except: abort(404) +@app.route('/set') +def get_proxied_path(): + if 'HTTP_X_FORWARDED_PREFIX' in request.environ: + pl = len(dict(request.headers)["X-Forwarded-Host"].split(", ")) + #prefix = request.environ['HTTP_X_FORWARDED_PREFIX'] + app.wsgi_app = ProxyFix(app.wsgi_app,x_for=pl,x_host=pl,x_port=pl,x_prefix=pl,x_proto=pl) + return redirect(url_for('new_paste')) + if __name__ == "__main__": app.run() -- cgit