Skip to content

Config


Flask Application Configuration

Configures Flask application with reverse proxy support and authentication settings.

Attributes:

Name Type Description
app Flask

Main Flask application instance

login LoginManager

Flask-Login manager instance

Warning

Should not be moved or links to the htmls may break

ReverseProxied

WSGI middleware for handling reverse proxy headers and URL rewriting.

This class modifies the WSGI environment to support running the application behind a reverse proxy, handling script names, URL schemes, and server names.

Attributes:

Name Type Description
app Flask

The Flask application instance to wrap

script_name str or None

Optional URL prefix for the application

scheme str or None

Optional URL scheme (http/https)

server str or None

Optional server name

Methods:

Name Description
__call__

Process the WSGI environment and handle reverse proxy headers

Source code in apps/annotator/code/config.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class ReverseProxied:
    """
    WSGI middleware for handling reverse proxy headers and URL rewriting.

    This class modifies the WSGI environment to support running the application
    behind a reverse proxy, handling script names, URL schemes, and server names.

    Attributes
    ----------
    app : flask.Flask
        The Flask application instance to wrap
    script_name : str or None
        Optional URL prefix for the application
    scheme : str or None
        Optional URL scheme (http/https)
    server : str or None
        Optional server name

    Methods
    -------
    __call__(environ, start_response)
        Process the WSGI environment and handle reverse proxy headers
    """

    def __init__(self, app, script_name=None, scheme=None, server=None):
        """
        Initialize the reverse proxy middleware.

        Parameters
        ----------
        app : flask.Flask
            Flask application instance
        script_name : str, optional
            URL prefix for the application
        scheme : str, optional
            URL scheme (http/https)
        server : str, optional
            Server name
        """
        self.app = app
        self.script_name = script_name
        self.scheme = scheme
        self.server = server

    def __call__(self, environ, start_response):
        """
        Process WSGI environment for reverse proxy support.

        Parameters
        ----------
        environ : dict
            WSGI environment dictionary
        start_response : callable
            WSGI start_response callable

        Returns
        -------
        callable
            Result of calling the wrapped WSGI application
        """
        script_name = environ.get('HTTP_X_SCRIPT_NAME', '') or self.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', '') or self.scheme
        if scheme:
            environ['wsgi.url_scheme'] = scheme
        server = environ.get('HTTP_X_FORWARDED_SERVER', '') or self.server
        if server:
            environ['HTTP_HOST'] = server
        return self.app(environ, start_response)

__call__(environ, start_response)

Process WSGI environment for reverse proxy support.

Parameters:

Name Type Description Default
environ dict

WSGI environment dictionary

required
start_response callable

WSGI start_response callable

required

Returns:

Type Description
callable

Result of calling the wrapped WSGI application

Source code in apps/annotator/code/config.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def __call__(self, environ, start_response):
    """
    Process WSGI environment for reverse proxy support.

    Parameters
    ----------
    environ : dict
        WSGI environment dictionary
    start_response : callable
        WSGI start_response callable

    Returns
    -------
    callable
        Result of calling the wrapped WSGI application
    """
    script_name = environ.get('HTTP_X_SCRIPT_NAME', '') or self.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', '') or self.scheme
    if scheme:
        environ['wsgi.url_scheme'] = scheme
    server = environ.get('HTTP_X_FORWARDED_SERVER', '') or self.server
    if server:
        environ['HTTP_HOST'] = server
    return self.app(environ, start_response)

__init__(app, script_name=None, scheme=None, server=None)

Initialize the reverse proxy middleware.

Parameters:

Name Type Description Default
app Flask

Flask application instance

required
script_name str

URL prefix for the application

None
scheme str

URL scheme (http/https)

None
server str

Server name

None
Source code in apps/annotator/code/config.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def __init__(self, app, script_name=None, scheme=None, server=None):
    """
    Initialize the reverse proxy middleware.

    Parameters
    ----------
    app : flask.Flask
        Flask application instance
    script_name : str, optional
        URL prefix for the application
    scheme : str, optional
        URL scheme (http/https)
    server : str, optional
        Server name
    """
    self.app = app
    self.script_name = script_name
    self.scheme = scheme
    self.server = server