I am trying to deploy restful API on google cloud. The code is working fine on my local. However, after the successful deployment of my application on google cloud when I am hitting the project URL, I am getting the following error:
Can't read from server. It may not have the appropriate access-control-origin settings.
I searched and found this thread similar to my issue. I followed it and created CORS for my project. Following is the created CORS on the project: [Ran - gsutil cors get gs://project-name]
[{"maxAgeSeconds": 86400, "method": ["GET", "POST", "OPTIONS"], "origin": ["*"], "responseHeader": ["Origin", "Accept", "X-Requested-With", "Authorization", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token"]}]
Following is the service:
from services import api
from services import Resource
from services import fields
import models
api = api.namespace(name='College', description='RESTFul API for College')
college = api.model('College', {'name' : fields.String('name'),
'short_name' : fields.String('short_name')})
@api.route('/college')
class CollegeList(Resource):
@api.marshal_with(college)
def get(self):
return models.College.query.all()
@api.expect(college)
def post(self):
name = api.payload.get('name')
short_name = api.payload.get('short_name')
college = models.College(name=name, short_name=short_name)
models.db.session.add(college)
models.db.session.commit()
return {'result' : name+' is Added!'}, 201
@api.route('/college/<int:id>')
class College(Resource):
@api.marshal_with(college)
def get(self, id):
return models.College.query.filter(models.College.id == id).one()
Is there anything needed in app.yaml to configure CORS?