fmt+debug
All checks were successful
Deploy on push / deploy (push) Successful in 5s

This commit is contained in:
Untone 2024-12-12 01:04:11 +03:00
parent 87506b0478
commit d02ae5bd3f
8 changed files with 32 additions and 5 deletions

5
.gitignore vendored
View File

@ -156,4 +156,7 @@ dokku_config
*.db
*.sqlite3
views.json
views.json
*.pem
*.key
*.crt

View File

@ -40,13 +40,16 @@ Backend service providing GraphQL API for content management system with reactio
### Setup
Start API server with `dev` key:
Start API server with `dev` keyword added and `mkcert` installed:
```shell
mkdir .venv
python3.12 -m venv .venv
poetry env use .venv/bin/python3.12
poetry update
mkcert -install
mkcert localhost
poetry run server.py dev
```

10
main.py
View File

@ -1,11 +1,13 @@
import asyncio
import os
import sys
from importlib import import_module
from os.path import exists
from ariadne import load_schema_from_path, make_executable_schema
from ariadne.asgi import GraphQL
from starlette.applications import Starlette
from starlette.middleware.cors import CORSMiddleware
from starlette.requests import Request
from starlette.responses import JSONResponse, Response
from starlette.routing import Route
@ -123,3 +125,11 @@ app = Starlette(
)
app.add_middleware(ExceptionHandlerMiddleware)
if "dev" in sys.argv:
app.add_middleware(
CORSMiddleware,
allow_origins=["https://localhost:3000"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

View File

@ -250,7 +250,7 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False):
same_slug_shout = session.query(Shout).filter(Shout.slug == slug).first()
shout_input["slug"] = slug
logger.info(f"shout#{shout_id} slug patched")
if filter(lambda x: x.id == author_id, [x for x in shout_by_id.authors]) or "editor" in roles:
logger.info(f"shout#{shout_id} is author or editor")
# topics patch

View File

@ -1,3 +1,6 @@
import sys
from pathlib import Path
from granian.constants import Interfaces
from granian.log import LogLevels
from granian.server import Granian
@ -20,6 +23,9 @@ if __name__ == "__main__":
backlog=2048,
)
if "dev" in sys.argv:
logger.info("dev mode, building ssl context")
granian_instance.build_ssl_context(cert=Path("localhost.pem"), key=Path("localhost-key.pem"), password=None)
granian_instance.serve()
except Exception as error:
logger.error(f"Granian error: {error}", exc_info=True)

View File

@ -93,6 +93,7 @@ def login_required(f):
Возвращает:
- Обернутую функцию с добавленной проверкой авторизации.
"""
@wraps(f)
async def decorated_function(*args, **kwargs):
info = args[1]
@ -124,6 +125,7 @@ def login_accepted(f):
Возвращает:
- Обернутую функцию с добавленной проверкой авторизации.
"""
@wraps(f)
async def decorated_function(*args, **kwargs):
info = args[1]

View File

@ -1,6 +1,7 @@
from asyncio.log import logger
from ariadne import MutationType, QueryType
import httpx
from ariadne import MutationType, QueryType
from settings import AUTH_URL
@ -10,6 +11,8 @@ resolvers = [query, mutation]
async def request_graphql_data(gql, url=AUTH_URL, headers=None):
if not url:
return None
if headers is None:
headers = {"Content-Type": "application/json"}
try:

View File

@ -1,7 +1,7 @@
import asyncio
from asyncio.log import logger
import os
import re
from asyncio.log import logger
from sqlalchemy import select
from starlette.endpoints import HTTPEndpoint