Сделал аналитику, пофиксил роуты, сделал SSL

This commit is contained in:
Данил 2024-10-18 19:58:32 +03:00
parent 05fb43c53a
commit a101eb7c1f
3 changed files with 39 additions and 9 deletions

View file

@ -1,11 +1,13 @@
FROM python:3.12 FROM python:3.12
WORKDIR /starlio-web WORKDIR /
COPY ./requirements.txt /starlio-web/requirements.txt COPY ./requirements.txt ./
RUN pip3 install --no-cache-dir --upgrade -r /starlio-web/requirements.txt RUN pip3 install --no-cache-dir --upgrade -r ./requirements.txt
COPY ./ /starlio-web/ COPY . .
EXPOSE 8000
CMD ["python", "main.py"] CMD ["python", "main.py"]

13
docker-compose.yaml Normal file
View file

@ -0,0 +1,13 @@
services:
starlio-web:
build: .
ports:
- '8000:8000'
restart: unless-stopped
volumes:
- './CertSSL:/CertSSL'
- './config.yaml:/config.yaml'
volumes:
starlio-web:
driver: local

25
main.py
View file

@ -1,14 +1,20 @@
import uvicorn
import yaml
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from starlette.responses import FileResponse from starlette.responses import FileResponse
from fastapi import FastAPI from fastapi import FastAPI
import uvicorn from src.middleware.plausible_analytics import PlausibleAnalytics
import os
config = yaml.safe_load(open('./config.yaml'))
from src.routes import index from src.routes import index
from src.routes import wallpaper from src.routes import wallpaper
app = FastAPI() app = FastAPI()
app.middleware('http')(PlausibleAnalytics())
app.include_router(index.router) app.include_router(index.router)
app.include_router(wallpaper.router) app.include_router(wallpaper.router)
@ -17,12 +23,12 @@ app.mount('/.well-known/', StaticFiles(directory='./.well-known/'))
@app.get('/app-ads.txt') @app.get('/app-ads.txt')
async def app_ads(req): async def app_ads():
return FileResponse('./app-ads.txt') return FileResponse('./app-ads.txt')
@app.get('/robots.txt') @app.get('/robots.txt')
async def robots_txt(req): async def robots_txt():
return FileResponse('./robots.txt') return FileResponse('./robots.txt')
@ -31,4 +37,13 @@ async def not_found(req, __):
return FileResponse('./src/web/html/error/404.html') return FileResponse('./src/web/html/error/404.html')
if __name__ == '__main__': if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=int(os.environ['PORT'])) 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
)