2024-10-23 17:01:26 +03:00
|
|
|
import http
|
|
|
|
|
2024-10-18 19:58:32 +03:00
|
|
|
import uvicorn
|
|
|
|
import yaml
|
|
|
|
|
2024-09-14 21:05:43 +03:00
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from starlette.responses import FileResponse
|
2024-09-18 21:31:09 +03:00
|
|
|
from fastapi import FastAPI
|
2024-10-18 19:58:32 +03:00
|
|
|
from src.middleware.plausible_analytics import PlausibleAnalytics
|
|
|
|
|
|
|
|
config = yaml.safe_load(open('./config.yaml'))
|
2024-09-14 21:05:43 +03:00
|
|
|
|
|
|
|
from src.routes import index
|
|
|
|
from src.routes import wallpaper
|
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
2024-10-23 17:01:26 +03:00
|
|
|
if config['analytics']['token']:
|
|
|
|
app.middleware('http')(PlausibleAnalytics())
|
2024-10-18 19:58:32 +03:00
|
|
|
|
2024-09-14 21:05:43 +03:00
|
|
|
app.include_router(index.router)
|
|
|
|
app.include_router(wallpaper.router)
|
|
|
|
|
|
|
|
app.mount('/static/', StaticFiles(directory='./src/web/static/'))
|
|
|
|
app.mount('/.well-known/', StaticFiles(directory='./.well-known/'))
|
|
|
|
|
|
|
|
|
2024-09-28 11:48:18 +03:00
|
|
|
@app.get('/app-ads.txt')
|
2024-10-18 19:58:32 +03:00
|
|
|
async def app_ads():
|
2024-09-14 21:05:43 +03:00
|
|
|
return FileResponse('./app-ads.txt')
|
|
|
|
|
2024-09-18 17:14:04 +03:00
|
|
|
|
2024-09-28 11:48:18 +03:00
|
|
|
@app.get('/robots.txt')
|
2024-10-18 19:58:32 +03:00
|
|
|
async def robots_txt():
|
2024-09-25 14:30:40 +03:00
|
|
|
return FileResponse('./robots.txt')
|
|
|
|
|
|
|
|
|
2024-09-14 21:05:43 +03:00
|
|
|
@app.exception_handler(404)
|
|
|
|
async def not_found(req, __):
|
2024-10-23 17:01:26 +03:00
|
|
|
return FileResponse('./src/web/html/error/404.html', status_code=http.HTTPStatus.NOT_FOUND)
|
2024-09-28 11:48:18 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2024-10-18 19:58:32 +03:00
|
|
|
uvicorn.run(app,
|
|
|
|
host=config['server']['host'],
|
|
|
|
port=8000,
|
|
|
|
ssl_keyfile=config['server']['ssl_privkey']
|
|
|
|
if config['server']['ssl_work']
|
|
|
|
else None,
|
|
|
|
ssl_certfile=config['server']['ssl_cert']
|
|
|
|
if config['server']['ssl_work']
|
|
|
|
else None
|
|
|
|
)
|