from starlette.applications import Starlette
from starlette.templating import Jinja2Templates
from starlette.routing import Route, Mount
from starlette.staticfiles import StaticFiles


templates = Jinja2Templates(directory='templates')


async def home(request):
    request_dir = dir(request)
    test = 2 ** 2
    return templates.TemplateResponse(
        'index.html',
        {'request': request, 'request_dir': request_dir, 'test': test},
    )


async def gn(request):
    return templates.TemplateResponse(
        'gn.html',
        {'request': request}
    )


routes = [
    Route('/', endpoint=home),
    Route('/gn', endpoint=gn),
    Mount('/static', StaticFiles(directory='../static'), name='static'),
    Mount('/public', StaticFiles(directory='../public'), name='public'),
    Mount(
        '/node_modules',
        StaticFiles(directory='../node_modules'),
        name='node_modules',
    ),
]

app = Starlette(debug=True, routes=routes)
