根据google端点API构建简单的服务。一切正常,但问题是通过backbone.js从其他主机调用API。所以我必须在服务器端允许“Access-Control-Allow-Origin:*”。
但是在文档或其他内容中找不到任何解决方案。 我试过在app.yaml中设置这个:
http_headers:
Access-Control-Allow-Origin: http://.*
但这仅适用于static_dir而不适用于脚本
感谢您的想法和帮助
from google.appengine.ext import endpoints
from google.appengine.ext import ndb
from protorpc import messages
from protorpc import message_types
from protorpc import remote
class SpotModel (ndb.Model):
description = ndb.StringProperty(required=True)
latitude = ndb.FloatProperty()
longitude = ndb.FloatProperty()
class Spot (messages.Message):
description = messages.StringField(1, required=True)
lat = messages.FloatField(2)
lng = messages.FloatField(3)
id = messages.IntegerField(4)
class SpotList (messages.Message):
items = messages.MessageField(Spot,1, repeated=True)
@endpoints.api(name="spots", version='v1',
description="API for create, update and list spots")
class SpotAPI(remote.Service):
@endpoints.method(Spot,Spot,
name='spot.insert',
path='spot',
http_method='POST')
def insertSpot(self, request):
newSpot = SpotModel(description = request.description,latitude = request.lat,longitude = request.lng)
newSpot.put()
return pareSpotToMessage(newSpot)
app = endpoints.api_server([SpotAPI])
答案 0 :(得分:0)
应该是
http_headers:
Access-Control-Allow-Origin: *