1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

CORS support

Fix #530
This commit is contained in:
Julien Duponchelle 2016-05-17 12:39:23 +02:00
parent b44c2ea713
commit 342bcdb5b6
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
3 changed files with 8 additions and 2 deletions

View File

@ -37,7 +37,6 @@ class Response(aiohttp.web.Response):
self._route = route self._route = route
self._output_schema = output_schema self._output_schema = output_schema
self._request = request self._request = request
headers['Access-Control-Allow-Origin'] = '*'
headers['X-Route'] = self._route headers['X-Route'] = self._route
headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__) headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__)
super().__init__(headers=headers, **kwargs) super().__init__(headers=headers, **kwargs)

View File

@ -24,6 +24,7 @@ import sys
import signal import signal
import asyncio import asyncio
import aiohttp import aiohttp
import aiohttp_cors
import functools import functools
import types import types
import time import time
@ -207,9 +208,14 @@ class WebServer:
log.debug("ENV %s=%s", key, val) log.debug("ENV %s=%s", key, val)
app = aiohttp.web.Application() 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(): for method, route, handler in Route.get_routes():
log.debug("Adding route: {} {}".format(method, route)) 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: for module in MODULES:
log.debug("Loading module {}".format(module.__name__)) log.debug("Loading module {}".format(module.__name__))
m = module.instance() m = module.instance()

View File

@ -1,5 +1,6 @@
jsonschema>=2.4.0 jsonschema>=2.4.0
aiohttp>=0.21.5 aiohttp>=0.21.5
aiohttp_cors>=0.4.0
Jinja2>=2.7.3 Jinja2>=2.7.3
raven>=5.2.0 raven>=5.2.0
psutil>=3.0.0 psutil>=3.0.0