diff options
author | Alex <alexta69@gmail.com> | 2021-01-26 22:08:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-26 22:08:24 +0200 |
commit | 5b72fe1ba39024377df47d01a2d6c01ce65d4186 (patch) | |
tree | baf7510a10023274c486b86f396a2462388de75f | |
parent | add 1440p quality (closes #11) (diff) | |
parent | Add support of CORS rules (diff) | |
download | metube-5b72fe1ba39024377df47d01a2d6c01ce65d4186.tar.gz metube-5b72fe1ba39024377df47d01a2d6c01ce65d4186.tar.bz2 metube-5b72fe1ba39024377df47d01a2d6c01ce65d4186.zip |
Merge pull request #17 from Rpsl/master
Add support of CORS rules
-rw-r--r-- | app/main.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/app/main.py b/app/main.py index 1287705..88d2525 100644 --- a/app/main.py +++ b/app/main.py @@ -97,10 +97,25 @@ if config.URL_PREFIX != '/': routes.static(config.URL_PREFIX + 'favicon/', 'favicon')
routes.static(config.URL_PREFIX, 'ui/dist/metube')
-
app.add_routes(routes)
+# https://github.com/aio-libs/aiohttp/pull/4615 waiting for release
+# @routes.options(config.URL_PREFIX + 'add')
+async def add_cors(request):
+ return web.Response(text=serializer.encode({"status": "ok"}))
+
+app.router.add_route('OPTIONS', config.URL_PREFIX + 'add', add_cors)
+
+
+async def on_prepare(request, response):
+ if 'Origin' in request.headers:
+ response.headers['Access-Control-Allow-Origin'] = request.headers['Origin']
+ response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
+
+app.on_response_prepare.append(on_prepare)
+
+
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
web.run_app(app, port=8081)
|