add cors and fix cyclic import
This commit is contained in:
parent
9d24f79436
commit
a09f40fa35
4 changed files with 27 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
from quart import Quart, g, request
|
||||
from quart_cors import cors
|
||||
from quart_schema import QuartSchema, RequestSchemaValidationError
|
||||
|
||||
from .blueprints import members_blueprint, users_blueprint
|
||||
|
@ -7,6 +8,13 @@ from .db.util import validate_token
|
|||
from .exceptions import ExpectedError
|
||||
|
||||
app = Quart(__name__)
|
||||
app = cors(
|
||||
app,
|
||||
allow_origin="*",
|
||||
allow_methods="*",
|
||||
allow_headers=["Content-Type", "Authorization", "User-Agent"],
|
||||
max_age=86400,
|
||||
)
|
||||
QuartSchema(app)
|
||||
|
||||
for bp in (users_blueprint, members_blueprint):
|
||||
|
@ -39,6 +47,5 @@ async def get_user_from_token():
|
|||
token, user = await validate_token(session, token)
|
||||
g.token = token
|
||||
g.user = user
|
||||
except Exception as e:
|
||||
print(e)
|
||||
except:
|
||||
raise
|
||||
|
|
|
@ -30,7 +30,7 @@ class User(Base):
|
|||
auth_methods: Mapped[list["AuthMethod"]] = relationship(
|
||||
back_populates="user", cascade="all, delete-orphan"
|
||||
)
|
||||
members: Mapped[list["Member"]] = relationship(
|
||||
members: Mapped[list["Member"]] = relationship( # noqa: F821
|
||||
back_populates="user", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
|
@ -38,11 +38,6 @@ class User(Base):
|
|||
return f"User(id={self.id!r}, username={self.username!r})"
|
||||
|
||||
|
||||
# Import Member here--it's needed for the back reference in User, but Member references User, so we can only import it
|
||||
# after User is initialized.
|
||||
from .member import Member # noqa: E402
|
||||
|
||||
|
||||
class Token(Base):
|
||||
__tablename__ = "tokens"
|
||||
|
||||
|
|
17
poetry.lock
generated
17
poetry.lock
generated
|
@ -966,6 +966,21 @@ werkzeug = ">=3.0.0"
|
|||
docs = ["pydata_sphinx_theme"]
|
||||
dotenv = ["python-dotenv"]
|
||||
|
||||
[[package]]
|
||||
name = "quart-cors"
|
||||
version = "0.7.0"
|
||||
description = "A Quart extension to provide Cross Origin Resource Sharing, access control, support"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "quart_cors-0.7.0-py3-none-any.whl", hash = "sha256:fa872cc94a2ae6b51a35b028ebca65c14069d7121d63a4caa3526ebbfb7c5a99"},
|
||||
{file = "quart_cors-0.7.0.tar.gz", hash = "sha256:d667a0f13b4ce6d9e926489de5d819780844fbff5b2cdea156bd8867dd426a37"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
quart = ">=0.15"
|
||||
|
||||
[[package]]
|
||||
name = "quart-schema"
|
||||
version = "0.19.1"
|
||||
|
@ -1240,4 +1255,4 @@ h11 = ">=0.9.0,<1"
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.11"
|
||||
content-hash = "a04cf866b1b5efd1f9484114b0e5924947a4044c7b7e70127f042778246c0ce6"
|
||||
content-hash = "820a4c895eee0304a7cb8572d441c377a3ecb82cb300aa5f21823c96413c0d6d"
|
||||
|
|
|
@ -22,6 +22,7 @@ uvicorn = "^0.28.0"
|
|||
asyncpg = "^0.29.0"
|
||||
environs = "^11.0.0"
|
||||
alembic = "^1.13.1"
|
||||
quart-cors = "^0.7.0"
|
||||
|
||||
[tool.poetry.group.dev]
|
||||
optional = true
|
||||
|
|
Loading…
Reference in a new issue