Google Cloud Functions enable CORS?

后端 未结 6 1675
暖寄归人
暖寄归人 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:40

    You can use the CORS express middleware.

    package.json

    npm install express --save
    npm install cors --save
    

    index.js

    'use strict';
    
    const functions = require('firebase-functions');
    const express = require('express');
    const cors = require('cors')({origin: true});
    const app = express();
    
    app.use(cors);
    app.get('*', (req, res) => {
        res.send(`Hello, world`);
    });
    
    exports.hello = functions.https.onRequest(app);
    

提交回复
热议问题