2024-12-15 10:51:32 +03:00
|
|
|
"""
|
|
|
|
This is the main application file for the chart service using FastAPI.
|
|
|
|
|
|
|
|
The application serves static files, provides endpoints for generating charts,
|
|
|
|
and integrates with Plausible Analytics for tracking usage.
|
|
|
|
"""
|
|
|
|
|
2024-10-06 20:55:06 +03:00
|
|
|
import os
|
2024-10-22 17:01:50 +03:00
|
|
|
|
2024-12-14 23:22:44 +03:00
|
|
|
import uvicorn
|
|
|
|
from fastapi import FastAPI
|
2024-10-06 20:55:06 +03:00
|
|
|
from starlette.staticfiles import StaticFiles
|
|
|
|
|
2024-12-14 23:22:44 +03:00
|
|
|
from chart.middleware.plausible_analytics import PlausibleAnalytics
|
|
|
|
from chart.routes import get_chart, get_chart_period
|
2024-12-15 10:51:32 +03:00
|
|
|
from chart.utils.load_config import load_config
|
2024-10-07 16:27:49 +03:00
|
|
|
|
2024-10-06 20:55:06 +03:00
|
|
|
app = FastAPI()
|
2024-12-15 10:51:32 +03:00
|
|
|
config = load_config('config.yaml')
|
2024-10-06 20:55:06 +03:00
|
|
|
|
2024-10-07 16:27:49 +03:00
|
|
|
if not os.path.exists('../charts'):
|
|
|
|
os.mkdir('../charts')
|
|
|
|
|
2024-10-06 20:55:06 +03:00
|
|
|
app.mount('/static/charts', StaticFiles(directory='../charts/'))
|
2024-10-17 20:56:10 +03:00
|
|
|
app.middleware('http')(PlausibleAnalytics())
|
2024-10-06 20:55:06 +03:00
|
|
|
|
2024-12-14 23:22:44 +03:00
|
|
|
app.include_router(get_chart.router)
|
|
|
|
app.include_router(get_chart_period.router)
|
2024-10-06 20:55:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2024-12-14 23:22:44 +03:00
|
|
|
uvicorn.run(
|
|
|
|
app,
|
|
|
|
host=config['server']['host'],
|
|
|
|
port=3030,
|
2024-12-15 10:51:32 +03:00
|
|
|
ssl_keyfile=
|
|
|
|
config['server']['ssl']['private_key']
|
|
|
|
if config['server']['ssl']['work']
|
|
|
|
else None,
|
|
|
|
ssl_certfile=
|
|
|
|
config['server']['ssl']['cert']
|
|
|
|
if config['server']['ssl']['work']
|
|
|
|
else None
|
2024-12-14 23:22:44 +03:00
|
|
|
)
|