aboutsummaryrefslogtreecommitdiffstats
path: root/backend/routes/index.py
blob: b37f3816e737513729703829124d7f3a5fc8ee7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Index route for the forms API.
"""
from starlette.requests import Request
from starlette.responses import JSONResponse

from backend.route import Route


class IndexRoute(Route):
    """
    Return a generic hello world message with some information to the client.

    Can be used as a healthcheck for Kubernetes or a frontend connection check.
    """

    name = "index"
    path = "/"

    def get(self, request: Request) -> JSONResponse:
        response_data = {
            "message": "Hello, world!",
            "client": request.client.host,
            "user": {
                "authenticated": False
            }
        }

        if request.user.is_authenticated:
            response_data["user"] = {
                "authenticated": True,
                "user": request.user.payload,
                "scopes": request.auth.scopes
            }

        return JSONResponse(response_data)