EN VI

Javascript - Shared code in a google cloud function in different regions?

2024-03-17 06:30:06
How to Javascript - Shared code in a google cloud function in different regions

I have the same exact google cloud function that I'm deploying to 2 different regions; for my European customers, none of their data can leave their country. Is there a way that I can share the code within my cloud function so that I can access the same code in the 2 different regions while having the 2 distinct endpoints?

   functions.http('helloHttp', async (req, res) => {
           //all the code I want to share is here!
   })

Solution:

You don't have to define your function implementation within the call to the functions.http method. You can simply put it in its own function or variable and pass it wherever you need it.

async function shared(req, res) {
    //all the code I want to share is here!
}

functions.http('helloHttp1', shared)
functions.http('helloHttp2', shared)
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login