CORS in Azure function on Raspberry pi 3B

六月ゝ 毕业季﹏ 提交于 2019-12-10 12:24:09

问题


I have Azure functions V2 running on my raspberry pi 3 in a docker container. I can access the functions via the ip-address of the pi in the network. My problem is that I can't access it from my website because of CORS.

If my Functions where running in the cloud, I could easily add CORS. Does anyone know how I could fix this on the raspberry pi? Update docker file or change files?


回答1:


CORS is basically just sending the appropriate headers in your response.

On Azure, this is taken care of by the platform itself but since you will be running/accessing the functions runtime directly from a container, you can just set them on the response object.

For example, if you are using NodeJS/JavaScript for your functions, set the headers using context.res

context.res = {
  status: 200,
  headers: {
    'Access-Control-Allow-Credentials': 'true',
    'Access-Control-Allow-Origin': '*', // Or the origins you want to allow requests from
    'Content-Type': 'application/json'
  },
  body: {
    just: 'some data'
  }
};


来源:https://stackoverflow.com/questions/54241282/cors-in-azure-function-on-raspberry-pi-3b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!