1

a have a build a simple service based on the google endpoints API. All works fine but the Problem is the API is called from other hosts via backbone.js. So I have to allow "Access-Control-Allow-Origin: *" on server side.

But a dont find any solution in the documentation or something else. I've tried to set up this in the app.yaml like:

http_headers:
    Access-Control-Allow-Origin: http://.*

but this only work for static_dir and not for scripts

Thanks for anay idea and help

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])
Stefan B.
  • 374
  • 3
  • 13
  • 1
    You should check out [`endpoints-proto-datastore`](https://endpoints-proto-datastore.appspot.com), it is exactly what your API needs and will reduce your code by half :) – bossylobster Mar 29 '13 at 18:28
  • What sort of issues are you having? CORS is fully enabled for Google Cloud Endpoints? – bossylobster Mar 29 '13 at 18:29

1 Answers1

0

It should be

http_headers:
    Access-Control-Allow-Origin: *