mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Middleware?
This commit is contained in:
parent
6734ae4d48
commit
a33144f2f9
5 changed files with 17 additions and 4 deletions
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "royalnet"
|
name = "royalnet"
|
||||||
version = "5.9.2"
|
version = "5.9.3"
|
||||||
description = "A multipurpose bot and web framework"
|
description = "A multipurpose bot and web framework"
|
||||||
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
||||||
license = "AGPL-3.0+"
|
license = "AGPL-3.0+"
|
||||||
|
|
|
@ -21,7 +21,6 @@ class ApiStar(PageStar, ABC):
|
||||||
|
|
||||||
tags: List[str] = []
|
tags: List[str] = []
|
||||||
|
|
||||||
|
|
||||||
async def page(self, request: Request) -> JSONResponse:
|
async def page(self, request: Request) -> JSONResponse:
|
||||||
if request.query_params:
|
if request.query_params:
|
||||||
data = request.query_params
|
data = request.query_params
|
||||||
|
|
|
@ -4,6 +4,8 @@ import logging
|
||||||
import importlib
|
import importlib
|
||||||
import uvicorn
|
import uvicorn
|
||||||
import starlette.applications
|
import starlette.applications
|
||||||
|
import starlette.middleware
|
||||||
|
import starlette.middleware.cors
|
||||||
import royalnet.alchemy as ra
|
import royalnet.alchemy as ra
|
||||||
import royalnet.herald as rh
|
import royalnet.herald as rh
|
||||||
import royalnet.utils as ru
|
import royalnet.utils as ru
|
||||||
|
@ -96,7 +98,16 @@ class Constellation:
|
||||||
self.events: Dict[str, rc.Event] = {}
|
self.events: Dict[str, rc.Event] = {}
|
||||||
"""A dictionary containing all :class:`~rc.Event` that can be handled by this :class:`Constellation`."""
|
"""A dictionary containing all :class:`~rc.Event` that can be handled by this :class:`Constellation`."""
|
||||||
|
|
||||||
self.starlette = starlette.applications.Starlette(debug=__debug__)
|
middleware = []
|
||||||
|
if constellation_cfg.get("cors_middleware", False):
|
||||||
|
log.info("CORS middleware: enabled")
|
||||||
|
middleware.append(
|
||||||
|
starlette.middleware.Middleware(starlette.middleware.cors.CORSMiddleware, {"allow_origins": ["*"]})
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
log.info("CORS middleware: disabled")
|
||||||
|
|
||||||
|
self.starlette = starlette.applications.Starlette(debug=__debug__, middleware=middleware)
|
||||||
"""The :class:`~starlette.Starlette` app."""
|
"""The :class:`~starlette.Starlette` app."""
|
||||||
|
|
||||||
self.stars: List[PageStar] = []
|
self.stars: List[PageStar] = []
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
semantic = "5.9.2"
|
semantic = "5.9.3"
|
||||||
|
|
|
@ -55,6 +55,9 @@ enabled = true
|
||||||
address = "0.0.0.0"
|
address = "0.0.0.0"
|
||||||
# The port on which the Constellation should run
|
# The port on which the Constellation should run
|
||||||
port = 44445
|
port = 44445
|
||||||
|
# If the CORS middleware should be enabled
|
||||||
|
# https://www.starlette.io/middleware/#corsmiddleware
|
||||||
|
cors_middleware = true
|
||||||
|
|
||||||
[Serfs]
|
[Serfs]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue