问题
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