Raspberry Pi 3B上Azure功能中的CORS

问题描述:

我在树莓派pi 3的docker容器中运行了Azure函数V2. 我可以通过网络中pi的ip地址访问这些功能. 我的问题是,由于CORS,我无法从我的网站访问它.

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.

如果我的功能在云中运行,则可以轻松添加CORS. 有谁知道我可以在树莓派上解决这个问题? 更新docker文件还是更改文件?

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?

CORS基本上只是在响应中发送适当的标头.

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

在Azure上,这是由平台本身解决的,但是由于您将直接从容器中运行/访问函数运行时,因此只需在响应对象上进行设置即可.

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.

例如,如果您将NodeJS/JavaScript用于函数,请使用context.res

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'
  }
};