Google云端函数启用CORS? [英] Google Cloud Functions enable CORS?

查看:218
本文介绍了Google云端函数启用CORS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了Hello World Google Cloud Functions教程,并收到了以下响应标头:

 连接→keep-alive 
Content-Length→14
Content-Type→text / plain; charset = utf-8
日期→2016年2月29日星期一07:02:37 GMT
Execution-Id→XbT-WC9lXKL-0
服务器→nginx


$ b

如何添加CORS头文件以便从我的网站调用我的函数?

  exports.helloWorld = function helloWorld(req =h2_lin>解决方案

,res){
res.set('Access-Control-Allow-Origin',*)
res.set('Access-Control-Allow-Methods','GET,POST')
res.status(200).send('weeee!);
};

然后您就可以像往常一样使用jquery / $:

  $。get(myUrl,(r)=> console.log(r))


I just finished the Hello World Google Cloud Functions tutorial and received the following response headers:

Connection → keep-alive
Content-Length → 14
Content-Type → text/plain; charset=utf-8
Date → Mon, 29 Feb 2016 07:02:37 GMT
Execution-Id → XbT-WC9lXKL-0
Server → nginx

How can I add the CORS headers to be able to call my function from my website?

解决方案

here we go:

exports.helloWorld = function helloWorld(req, res) {  
  res.set('Access-Control-Allow-Origin', "*")
  res.set('Access-Control-Allow-Methods', 'GET, POST')
  res.status(200).send('weeee!);
};

then you can jquery/whatever it as usual:

$.get(myUrl, (r) => console.log(r))

这篇关于Google云端函数启用CORS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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