From 342bcdb5b6808381c5a297f9f8ae7b3062a86d1b Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 17 May 2016 12:39:23 +0200 Subject: [PATCH] CORS support Fix #530 --- gns3server/web/response.py | 1 - gns3server/web/web_server.py | 8 +++++++- requirements.txt | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gns3server/web/response.py b/gns3server/web/response.py index cba7308d..7ba0bd8a 100644 --- a/gns3server/web/response.py +++ b/gns3server/web/response.py @@ -37,7 +37,6 @@ class Response(aiohttp.web.Response): self._route = route self._output_schema = output_schema self._request = request - headers['Access-Control-Allow-Origin'] = '*' headers['X-Route'] = self._route headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__) super().__init__(headers=headers, **kwargs) diff --git a/gns3server/web/web_server.py b/gns3server/web/web_server.py index d43c88c1..d6da3845 100644 --- a/gns3server/web/web_server.py +++ b/gns3server/web/web_server.py @@ -24,6 +24,7 @@ import sys import signal import asyncio import aiohttp +import aiohttp_cors import functools import types import time @@ -207,9 +208,14 @@ class WebServer: log.debug("ENV %s=%s", key, val) app = aiohttp.web.Application() + # Allow CORS for this domains + cors = aiohttp_cors.setup(app, defaults={ + # Default web server for web gui dev + "http://localhost:8080": aiohttp_cors.ResourceOptions(expose_headers="*", allow_headers="*") + }) for method, route, handler in Route.get_routes(): log.debug("Adding route: {} {}".format(method, route)) - app.router.add_route(method, route, handler) + cors.add(app.router.add_route(method, route, handler)) for module in MODULES: log.debug("Loading module {}".format(module.__name__)) m = module.instance() diff --git a/requirements.txt b/requirements.txt index 59e6145b..3b8e0fd2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ jsonschema>=2.4.0 aiohttp>=0.21.5 +aiohttp_cors>=0.4.0 Jinja2>=2.7.3 raven>=5.2.0 psutil>=3.0.0