forked from PostmonAPI/postmon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
27 lines (21 loc) · 801 Bytes
/
utils.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
import bottle
from slugify import slugify
def slug(value):
value = slugify(value, only_ascii=True, spaces=True)
return value.upper()
class EnableCORS(object):
name = 'enable_cors'
api = 2
def apply(self, fn, context):
def _enable_cors(*args, **kwargs):
# set CORS headers
bottle.response.headers.update({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
'Access-Control-Allow-Headers':
', '.join(bottle.request.headers.keys())
})
if bottle.request.method != 'OPTIONS':
# actual request; reply with the actual response
return fn(*args, **kwargs)
return _enable_cors