forked from osm-fr/osmose-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbottle_cors.py
36 lines (25 loc) · 900 Bytes
/
bottle_cors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'''
'''
__author__ = "Frederic Rodrigo"
__version__ = '0.1'
__license__ = 'MIT'
### CUT HERE (see setup.py)
from bottle import request, response
class CorsPlugin(object):
'''
'''
name = 'cors'
api = 2
def __init__(self, allow_origin='*', preflight_methods=['GET', 'POST', 'PUT', 'DELETE']):
self.allow_origin = allow_origin
self.preflight_methods = ', '.join(preflight_methods)
def apply(self, callback, route):
def wrapper(*args, **kwargs):
# set CORS headers
response.headers['Access-Control-Allow-Origin'] = self.allow_origin
response.headers['Access-Control-Allow-Methods'] = self.preflight_methods
if request.method != 'OPTIONS':
# actual request; reply with the actual response
return callback(*args, **kwargs)
return wrapper
Plugin = CorsPlugin