0

This is similar to a previous question of mine

I'm testing Cloud Functions in a Firebase Node.js project using Express apps, and don't know how to add query parameters to my test.

Sample code:

const logUUID = (req, res) => {
    console.log("This function is executing!")
    res.send(req.params.uuid)
}

test_app.use("/log_uuid", logUUID)
exports.test = functions.https.onRequest(test_app)

I am calling it through this:

test.get("/logParams")

Which does indeed log

This function is executing!

I don't know how to pass in a 'uuid' query parameter, even after reading the firebase docs and the request readme linked in the firebase docs. I've tried everything I could come up with:

test.get("/logParams?uuid=1234")
test.get("/logParams",{uuid:1234})
...

How can I do this?

RedKnight91
  • 340
  • 3
  • 17

1 Answers1

2

This can be done with a 'qs' argument:

    test.get("/logParams", qs: {uuid:"1234"})

Or including the query string in the path itself

    test.get("/logParams?uuid=1234")

The problem in your code is that instead of req.params.uuid you should use req.query.uuid

See the difference between req.params and req.query

RedKnight91
  • 340
  • 3
  • 17
Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
  • Unfortunately this does not work (it just produces no output) – RedKnight91 Nov 26 '19 at 04:27
  • It's odd that it does not work as the firebase docs suggest that the shell works exactly like request.js, and from I what I just found here the solution should be what you said https://stackoverflow.com/a/16903926/6763963 – RedKnight91 Nov 26 '19 at 05:00
  • Couldn't it be that it is working but I'm not reading the qs correctly in the function? I'll try again when I get home – RedKnight91 Nov 26 '19 at 05:03
  • 1
    Ok I'm starting to believe I need to use req.query instead of req.params – RedKnight91 Nov 26 '19 at 05:46