include Access-Control-Allow-Origin in 404 not found response

This commit is contained in:
j 2016-05-27 11:51:47 +02:00
parent d20620a716
commit 7fdaf6d1ce

View file

@ -8,7 +8,7 @@ from django.shortcuts import render_to_response
from django.template import RequestContext from django.template import RequestContext
from django.conf import settings from django.conf import settings
from ..shortcuts import render_to_json_response, json_response from ..shortcuts import render_to_json_response, json_response, HttpErrorJson
from actions import actions from actions import actions
@ -31,7 +31,9 @@ def api(request):
'settings': settings, 'settings': settings,
'sitename': settings.SITENAME 'sitename': settings.SITENAME
}) })
return render_to_response('api.html', context) response = render_to_response('api.html', context)
response['Access-Control-Allow-Origin'] = '*'
return response
if request.META.get('CONTENT_TYPE') == 'application/json': if request.META.get('CONTENT_TYPE') == 'application/json':
r = json.loads(request.body) r = json.loads(request.body)
action = r['action'] action = r['action']
@ -45,7 +47,10 @@ def api(request):
else: else:
f = actions.get(action) f = actions.get(action)
if f: if f:
try:
response = f(request, data) response = f(request, data)
except HttpErrorJson as e:
response = render_to_json_response(e.response)
else: else:
response = render_to_json_response(json_response(status=400, response = render_to_json_response(json_response(status=400,
text='Unknown action %s' % action)) text='Unknown action %s' % action))