Raspberry Pi 3B上Azure功能中的CORS [英] CORS in Azure function on Raspberry pi 3B

查看:50
本文介绍了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'
  }
};

这篇关于Raspberry Pi 3B上Azure功能中的CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆