test-asgi
This commit is contained in:
parent
91025d453f
commit
7c8b58d613
|
@ -1,3 +1,6 @@
|
|||
[0.2.21]
|
||||
- replace uvicorn with granian
|
||||
|
||||
[0.2.20]
|
||||
- added logger
|
||||
- typing revision
|
||||
|
|
|
@ -19,4 +19,4 @@ RUN apt-get update && apt-get install -y gcc curl && \
|
|||
poetry install --no-dev
|
||||
|
||||
# Run server.py when the container launches
|
||||
CMD ["python", "server.py"]
|
||||
CMD ["python", "main.py"]
|
||||
|
|
10
main.py
10
main.py
|
@ -2,8 +2,11 @@ import os
|
|||
from importlib import import_module
|
||||
from os.path import exists
|
||||
|
||||
from granian import Granian
|
||||
|
||||
from ariadne import load_schema_from_path, make_executable_schema
|
||||
from ariadne.asgi import GraphQL
|
||||
from granian.server import Interfaces
|
||||
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
|
||||
from sentry_sdk.integrations.ariadne import AriadneIntegration
|
||||
from sentry_sdk.integrations.redis import RedisIntegration
|
||||
|
@ -55,3 +58,10 @@ async def shutdown():
|
|||
|
||||
app = Starlette(debug=True, on_startup=[start_up], on_shutdown=[shutdown])
|
||||
app.mount("/", GraphQL(schema, debug=True))
|
||||
|
||||
if __name__ == "__main__":
|
||||
Granian(
|
||||
target="main:app",
|
||||
interface=Interfaces.ASGI,
|
||||
reload=True
|
||||
).serve()
|
||||
|
|
|
@ -10,10 +10,10 @@ sentry-sdk = "^1.39.1"
|
|||
redis = { extras = ["hiredis"], version = "^5.0.1" }
|
||||
ariadne = "^0.21"
|
||||
starlette = "^0.34.0"
|
||||
uvicorn = "^0.24"
|
||||
itsdangerous = "^2.1.2"
|
||||
aiohttp = "^3.9.1"
|
||||
requests = "^2.31.0"
|
||||
granian = "^1.0.1"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
setuptools = "^69.0.2"
|
||||
|
|
59
server.py
59
server.py
|
@ -1,59 +0,0 @@
|
|||
import sys
|
||||
|
||||
import uvicorn
|
||||
from uvicorn.main import logger
|
||||
|
||||
from settings import PORT
|
||||
|
||||
log_settings = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": True,
|
||||
"formatters": {
|
||||
"default": {
|
||||
"()": "uvicorn.logging.DefaultFormatter",
|
||||
"fmt": "%(levelprefix)s %(message)s",
|
||||
"use_colors": None,
|
||||
},
|
||||
"access": {
|
||||
"()": "uvicorn.logging.AccessFormatter",
|
||||
"fmt": '%(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s',
|
||||
},
|
||||
},
|
||||
"handlers": {
|
||||
"default": {
|
||||
"formatter": "default",
|
||||
"class": "logging.StreamHandler",
|
||||
"stream": "ext://sys.stderr",
|
||||
},
|
||||
"access": {
|
||||
"formatter": "access",
|
||||
"class": "logging.StreamHandler",
|
||||
"stream": "ext://sys.stdout",
|
||||
},
|
||||
},
|
||||
"loggers": {
|
||||
"uvicorn": {"handlers": ["default"], "level": "INFO"},
|
||||
"uvicorn.error": {"level": "INFO", "handlers": ["default"], "propagate": True},
|
||||
"uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": False},
|
||||
},
|
||||
}
|
||||
|
||||
local_headers = [
|
||||
("Access-Control-Allow-Methods", "GET, POST, OPTIONS, HEAD"),
|
||||
("Access-Control-Allow-Origin", "https://localhost:3000"),
|
||||
(
|
||||
"Access-Control-Allow-Headers",
|
||||
"DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization",
|
||||
),
|
||||
("Access-Control-Expose-Headers", "Content-Length,Content-Range"),
|
||||
("Access-Control-Allow-Credentials", "true"),
|
||||
]
|
||||
|
||||
|
||||
def exception_handler(_et, exc, _tb):
|
||||
logger.error(..., exc_info=(type(exc), exc, exc.__traceback__))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.excepthook = exception_handler
|
||||
uvicorn.run("main:app", host="0.0.0.0", port=PORT, proxy_headers=True, server_header=True)
|
Loading…
Reference in New Issue
Block a user