summaryrefslogtreecommitdiffstats
path: root/ttun_server/__init__.py
blob: f5d6b459bc3855859c2a9ba4fad6bf9ea8811ab7 (plain)
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
import logging
import os

from fastapi import FastAPI
from starlette.middleware.authentication import AuthenticationMiddleware
from starlette.routing import Host, Route, WebSocketRoute, Mount

from authentication.backend import BearerTokenAuthBackend
from authentication.endpoints import authentication, oauth
from proxy import app as proxy_app
from ttun_server.endpoints import health
from ttun_server.websockets import tunnel

logging.basicConfig(level=getattr(logging, os.environ.get('LOG_LEVEL', 'INFO')))

app = FastAPI(
    debug=True,
    routes=[
        Mount('/auth/', app=authentication),
        Mount('/oauth/', app=oauth),
        WebSocketRoute(
            '/tunnel/',
            endpoint=tunnel,
        ),
        Route('/health/', endpoint=health),
        Host(f'{{subdomain}}.{os.environ['TUNNEL_DOMAIN']}', app=proxy_app)
    ]
)

app.add_middleware(AuthenticationMiddleware, backend=BearerTokenAuthBackend())

try:
    from ._version import version
    __version__ = version
except ImportError:
    __version__ = 'development'