How can i test from the emulator a cloud function?

Viewed 35

i have a cloud function like this

exports.isWhite = functions.https.onRequest((request, response) => {
  return cors(request, response, async () => {
    try {
      const { query } = request
      let { address } = query
      address = address.toLowerCase()

but i dont know how can i test it from the emulator?

i put this url http://localhost:5001/roor-dev-ff624/us-central1/isWhitelisted on my browser, how can i pass the address? because i am getting this error:

"[ !!! ] Error:  TypeError: Cannot read property 'toLowerCase' of undefined\n 
1 Answers

You are looking for Query String parameters. To pass the address that way, try changing the URL to:

http://localhost:5001/roor-dev-ff624/us-central1/isWhitelisted?address=some_address

You can use optional chaining to avoid that error:

const address = request.query.address?.toLowerCase();
Related