Closed warownia1 closed 4 years ago
url_for works incorrectly when slivka is served under a sub-path /slivka Path prefix can be set using SCRIPT_NAME environ variable passed to flask app in wsgi handler:
url_for
/slivka
SCRIPT_NAME
class PrefixMiddleware: def __init__(self, app, prefix=''): self.app = app self.prefix = prefix def __call__(self, environ, start_response): if environ['PATH_INFO'].startswith(self.prefix): environ['PATH_INFO'] = environ['PATH_INFO'][len(self.prefix):] or '/' environ['SCRIPT_NAME'] = self.prefix return self.app(environ, start_response) else: start_response('404', [('Content-Type', 'text/plain')]) return ["No prefix".encode()] app.wsgi_app = PrefixMiddleware(app.wsgi_app, "/slivka")
Similarly you can run gunicorn with -e SCRIPT_NAME=/slivka or uwsgi with --manage-script-name --mount /slivka=wsgi:app
-e SCRIPT_NAME=/slivka
--manage-script-name --mount /slivka=wsgi:app
See also: https://gist.github.com/Larivact/1ee3bad0e53b2e2c4e40
url_for
works incorrectly when slivka is served under a sub-path/slivka
Path prefix can be set usingSCRIPT_NAME
environ variable passed to flask app in wsgi handler:Similarly you can run gunicorn with
-e SCRIPT_NAME=/slivka
or uwsgi with--manage-script-name --mount /slivka=wsgi:app
See also: https://gist.github.com/Larivact/1ee3bad0e53b2e2c4e40