mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[fix] CORS Prefech OPTIONS
This commit is contained in:
parent
4239f466f8
commit
3f8f573d7e
1 changed files with 18 additions and 7 deletions
|
@ -728,12 +728,10 @@ class Interface:
|
||||||
app = Bottle(autojson=True)
|
app = Bottle(autojson=True)
|
||||||
|
|
||||||
# Wrapper which sets proper header
|
# Wrapper which sets proper header
|
||||||
def apiheader(callback):
|
# Doesn't work if the HTTPResponse has been raised
|
||||||
def wrapper(*args, **kwargs):
|
# like HTTP Error
|
||||||
response.set_header("Access-Control-Allow-Origin", "*")
|
def apiheader():
|
||||||
return callback(*args, **kwargs)
|
response.set_header("Access-Control-Allow-Origin", "*")
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
# Attempt to retrieve and set locale
|
# Attempt to retrieve and set locale
|
||||||
def api18n(callback):
|
def api18n(callback):
|
||||||
|
@ -749,7 +747,7 @@ class Interface:
|
||||||
|
|
||||||
# Install plugins
|
# Install plugins
|
||||||
app.install(filter_csrf)
|
app.install(filter_csrf)
|
||||||
app.install(apiheader)
|
app.add_hook("after_request", apiheader)
|
||||||
app.install(api18n)
|
app.install(api18n)
|
||||||
actionsmapplugin = _ActionsMapPlugin(actionsmap, log_queues)
|
actionsmapplugin = _ActionsMapPlugin(actionsmap, log_queues)
|
||||||
app.install(actionsmapplugin)
|
app.install(actionsmapplugin)
|
||||||
|
@ -758,6 +756,19 @@ class Interface:
|
||||||
self.display = actionsmapplugin.display
|
self.display = actionsmapplugin.display
|
||||||
self.prompt = actionsmapplugin.prompt
|
self.prompt = actionsmapplugin.prompt
|
||||||
|
|
||||||
|
# Answer to prefetch OPTIONS request to make CORS working
|
||||||
|
# and our damned swagger api documentation tool
|
||||||
|
def options_prefetch_cors():
|
||||||
|
response = HTTPResponse("", 200)
|
||||||
|
response.set_header("Access-Control-Allow-Origin", "*")
|
||||||
|
response.set_header("Access-Control-Allow-Headers", "x-requested-with")
|
||||||
|
response.set_header("Allow", "GET, POST, PUT, DELETE, OPTIONS")
|
||||||
|
return response
|
||||||
|
|
||||||
|
app.route('/<:re:.*>', method="OPTIONS",
|
||||||
|
callback=options_prefetch_cors, skip=["actionsmap"])
|
||||||
|
|
||||||
|
|
||||||
# Append additional routes
|
# Append additional routes
|
||||||
# TODO: Add optional authentication to those routes?
|
# TODO: Add optional authentication to those routes?
|
||||||
for (m, p), c in routes.items():
|
for (m, p), c in routes.items():
|
||||||
|
|
Loading…
Add table
Reference in a new issue