Created
September 15, 2017 18:45
-
-
Save yakneens/2e419127f24a3c57f173382b3e8fd075 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
class URLPrefixMiddleware(object): | |
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):] | |
environ['SCRIPT_NAME'] = self.prefix | |
return self.app(environ, start_response) | |
else: | |
start_response('404', [('Content-Type', 'text/plain')]) | |
return ["This url does not belong to the app.".encode()] | |
def create_app(config=None): | |
app = Flask(__name__) | |
app.wsgi_app = URLPrefixMiddleware(app.wsgi_app, prefix=str(configuration.get("webserver", "URL_PREFIX"))) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment