#228 WSGI: Add middleware for OpenShift deployment to suffix /blockerbugs to the root
Merged 2 years ago by frantisekz. Opened 2 years ago by frantisekz.

file modified
+21
@@ -119,6 +119,27 @@ 

  # https://stackoverflow.com/questions/63542818/mypy-and-inheriting-from-a-class-that-is-an-attribute-on-an-instance

  BaseModel: DefaultMeta = db.Model

  

+ 

+ # === Infra tweaks ===

+ 

+ class PrefixMiddleware(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()]

+ 

+ 

+ if openshift:

+     app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/blockerbugs')  # type: ignore[assignment]

+ 

  # "Hotfix" for proxy handling on current deployment, my guess is that the proxy

  # server is set differently than it was, but what do I know...

  if app.config["BEHIND_PROXY"]:

Running blockerbugs on OpenShift on non-root of the domain causes weird stuff to happen. This adds /blockerbugs/ as a suffix for Flask.

I don't have any preference for the place of the PrefixMiddleware class, will happily move that somewhere else.

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

1 new commit added

  • move openshift tweaks lower in __init__
2 years ago

I'm not happy about so much openshift-related hardcoded things, but at this moment we don't know how to better solve it, so keep it, and lets look at it later. I moved the code a bit more down in __init__ to make it more readable. If this still works for you, please squash and merge, thanks.

Build succeeded.

rebased onto 2255fc0

2 years ago

Build succeeded.

Pull-Request has been merged by frantisekz

2 years ago
Metadata