diff --git a/Pipfile b/Pipfile index 196f485..0e13604 100644 --- a/Pipfile +++ b/Pipfile @@ -9,7 +9,6 @@ itsdangerous = "==0.24" asyncpg = "==0.16.0" websockets = "==6.0" Quart = "==0.6.4" -Quart-CORS = "==0.1.0" Earl-ETF = "==2.1.2" logbook = "*" Cerberus = "==1.2" diff --git a/Pipfile.lock b/Pipfile.lock index 216f61a..66267b7 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "585c48e434f1bceb0e37614f8f5eee7d7c63c75bde89c0e291120cc0fcd0a655" + "sha256": "5c6bee74cdf32ed63ef221d9de5b9074678f69e1401e9267aa2d24159fac22c4" }, "pipfile-spec": 6, "requires": { @@ -256,14 +256,6 @@ "index": "pypi", "version": "==0.6.4" }, - "quart-cors": { - "hashes": [ - "sha256:8727d56c91c8056b605cfd63774c9953215d955604a2a59fa23d1187b3a8728f", - "sha256:e66ea9a371d58356277ef1661fdcc8c25e796b5a269c4493d59472a18aa8ba32" - ], - "index": "pypi", - "version": "==0.1.0" - }, "six": { "hashes": [ "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", diff --git a/run.py b/run.py index a9d081f..aec1e1d 100644 --- a/run.py +++ b/run.py @@ -5,7 +5,6 @@ import asyncpg import logbook import websockets from quart import Quart, g, jsonify -from quart_cors import cors from logbook import StreamHandler, Logger from logbook.compat import redirect_logging @@ -26,7 +25,6 @@ redirect_logging() def make_app(): app = Quart(__name__) - app = cors(app) app.config.from_object(f'config.{config.MODE}') is_debug = app.config.get('DEBUG', False) app.debug = is_debug @@ -38,12 +36,27 @@ def make_app(): app = make_app() -app.register_blueprint(gateway, url_prefix='/api/v6') -app.register_blueprint(auth, url_prefix='/api/v6') -app.register_blueprint(users, url_prefix='/api/v6/users') -app.register_blueprint(guilds, url_prefix='/api/v6/guilds') -app.register_blueprint(channels, url_prefix='/api/v6/channels') -app.register_blueprint(webhooks, url_prefix='/api/v6') + +bps = { + gateway: None, + auth: '/auth', + users: '/users', + guilds: '/guilds', + channels: '/channels', + webhooks: None +} + +for bp, suffix in bps.items(): + suffix = suffix or '' + app.register_blueprint(bp, url_prefix=f'/api/v6{suffix}') + + +@app.after_request +async def app_after_request(resp): + resp.headers['Access-Control-Allow-Origin'] = '*' + resp.headers['Access-Control-Allow-Headers'] = '*' + resp.headers['Access-Control-Allow-Methods'] = '*' + return resp @app.before_serving