- Fix static files not loading due to volume mount conflict - Remove problematic volume mount from docker-compose.yml - Add __init__.py files to make Python packages - Fix all import statements to use relative imports - Update start.sh to use correct module name - Update config.py with correct default paths and values - Ensure all environment variables are properly loaded from .env file
75 lines
2.6 KiB
Python
75 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
LogBoard+ - Страницы API
|
|
Автор: Сергей Антропов
|
|
Сайт: https://devops.org.ru
|
|
"""
|
|
|
|
from fastapi import APIRouter, Request, Depends, HTTPException
|
|
from fastapi.responses import HTMLResponse, RedirectResponse, PlainTextResponse
|
|
|
|
from core.auth import verify_token, get_current_user
|
|
from core.config import templates, AJAX_UPDATE_INTERVAL, DEFAULT_TAIL, SKIP_UNHEALTHY
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/", response_class=HTMLResponse)
|
|
async def index(request: Request):
|
|
"""Главная страница приложения"""
|
|
# Проверяем наличие токена в cookie
|
|
access_token = request.cookies.get("access_token")
|
|
if not access_token:
|
|
return RedirectResponse(url="/login")
|
|
|
|
# Проверяем валидность токена
|
|
username = verify_token(access_token)
|
|
if not username:
|
|
return RedirectResponse(url="/login")
|
|
|
|
return templates.TemplateResponse("index.html", {"request": request})
|
|
|
|
@router.get("/login", response_class=HTMLResponse)
|
|
async def login_page(request: Request):
|
|
"""Страница входа"""
|
|
return templates.TemplateResponse("login.html", {"request": request})
|
|
|
|
@router.get("/healthz", response_class=PlainTextResponse)
|
|
def healthz():
|
|
"""Health check endpoint"""
|
|
return "ok"
|
|
|
|
@router.get("/favicon.ico")
|
|
async def favicon():
|
|
"""Favicon redirect"""
|
|
from fastapi.responses import RedirectResponse
|
|
return RedirectResponse(url="/static/images/favicon.ico")
|
|
|
|
|
|
|
|
# Маршруты для тестирования страниц ошибок (только в режиме разработки)
|
|
@router.get("/test/error/404")
|
|
async def test_404_error():
|
|
"""Тест страницы ошибки 404"""
|
|
raise HTTPException(status_code=404, detail="Тестовая ошибка 404")
|
|
|
|
@router.get("/test/error/401")
|
|
async def test_401_error():
|
|
"""Тест страницы ошибки 401"""
|
|
raise HTTPException(status_code=401, detail="Тестовая ошибка 401")
|
|
|
|
@router.get("/test/error/403")
|
|
async def test_403_error():
|
|
"""Тест страницы ошибки 403"""
|
|
raise HTTPException(status_code=403, detail="Тестовая ошибка 403")
|
|
|
|
@router.get("/test/error/500")
|
|
async def test_500_error():
|
|
"""Тест страницы ошибки 500"""
|
|
raise HTTPException(status_code=500, detail="Тестовая ошибка 500")
|
|
|
|
@router.get("/test/error/general")
|
|
async def test_general_error():
|
|
"""Тест общей ошибки"""
|
|
raise Exception("Тестовая общая ошибка")
|