Google Cloud Functions enable CORS?

后端 未结 6 1672
暖寄归人
暖寄归人 2020-12-05 17:08

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

Connection → keep-alive
Content-Length → 14
Cont         


        
6条回答
  •  遥遥无期
    2020-12-05 17:50

    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))
    

提交回复
热议问题