1

a 有一个基于谷歌端点 API 的简单服务。一切正常,但问题是API是通过backbone.js从其他主机调用的。所以我必须在服务器端允许“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])
4

1 回答 1

0

它应该是

http_headers:
    Access-Control-Allow-Origin: *
于 2017-05-03T11:16:52.080 回答