如何在Firebase函数中将参数传递给cors

时间:2019-11-18 21:49:50

标签: node.js firebase cors axios google-cloud-functions

我正在尝试将基本字符串参数发送到firebase函数中的cors。但是,在没有cors爆发并阻止我的请求的情况下,我找不到传递参数的方法。

const functions = require('firebase-functions');
const cors = require('cors')({origin:true})

exports.sendMail = functions.https.onRequest((request, response) => {
  cors(request, response,() =>{
    var variableA = request.body.A
    var variableB = request.body.B
    var variableC = reques.body.C

    response.send("Function run completed")
  })

正在使用axios.get()调用Firebase函数

axios.get('someURL', {
            A:variableA,
            B:variableB,
            C:variableC
        })
        .then(res => {
            const output = res.data;
            console.log("message output = " + output)
        })

request和firebase函数正常运行且符合预期。但是我不知道如何正确传递参数。有人知道该怎么做吗?

重要的编辑! -我应该补充一点,上面代码中显示的方法会导致参数未定义。如果我尝试以任何方式(第一对请求和响应对象)从axios调用中引用请求和响应对象,那就是当cors错误爆发时。

1 个答案:

答案 0 :(得分:2)

您应该使用adjacency_lists = defaultdict(set) for ind, coord in enumerate(coordinates): for other_coord in coordinates[ind:]: if abs((coord[0] - other_coord[0])) <= 1 or abs((coord[1] - other_coord[1])) <= 1: adjacency_lists[coord].add(other_coord) adjacency_lists[other_coord].add(coord) >> adjacency_lists {(1, 0): {(1, 0), (1, 1), (1, 2), (2, 2), (7, 1)}, (1, 1): {(1, 0),(1, 1),(1, 2),(2, 2),(3, 2),(4, 2),(6, 2),(7, 1),(7, 2)}, (7, 1): {(1, 0),(1, 1),(1, 2),(2, 2),(3, 2),(4, 2),(6, 2),(7, 1),(7, 2)}, (1, 2): {(1, 0),(1, 1),(1, 2),(2, 2),(3, 2),(4, 2),(4, 3),(6, 2),(7, 1),(7, 2)}, (2, 2): {(1, 0),(1, 1),(1, 2),(2, 2),(3, 2),(4, 2),(4, 3),(6, 2),(7, 1),(7, 2)}, (3, 2): {(1, 1),(1, 2),(2, 2),(3, 2),(4, 2),(4, 3),(6, 2),(7, 1),(7, 2)},(4, 2): {(1, 1),(1, 2),(2, 2),(3, 2),(4, 2),(4, 3),(6, 2),(7, 1),(7, 2)}, (6, 2): {(1, 1),(1, 2),(2, 2),(3, 2),(4, 2),(4, 3),(6, 2),(7, 1),(7, 2)}, (7, 2): {(1, 1),(1, 2),(2, 2),(3, 2),(4, 2),(4, 3),(6, 2),(7, 1),(7, 2)}, (4, 3): {(1, 2), (2, 2), (3, 2), (4, 2), (4, 3), (6, 2), (7, 2)}} :通过执行axios.post()axios.get()不会传递给Cloud Function。

body