1
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp()

exports.sendChatMsgNotification = functions.region('europe-west1')
firestore
  .document('chats/{idChat}/messages/{idMessage}')
  .onCreate((snap, context) => {
    console.log('----------------start function--------------------')

I am trying to deploy my Firebase cloud function into europe-west1 region because the default is us-central1, but I am always getting errors.

Yes, I have already tried to follow the official documentation https://firebase.google.com/docs/functions/locations#android. I just have no idea how to apply it correctly. I have tried many times.

If someone can just show me how to apply the correct way using my code above, would be highly appreciated!

3
  • What errors do you get? Commented Jul 10, 2022 at 19:40
  • 2
    Are you missing a dot (.) after the region and before firestore? Commented Jul 10, 2022 at 20:30
  • Oh it was really just the dot (.) after all! How have I not noticed this all the time. Thanks for pointing it out! Commented Jul 10, 2022 at 22:08

3 Answers 3

3

Before

exports.sendChatMsgNotification = functions.region('europe-west1')
firestore

After (working)

exports.sendChatMsgNotification = functions.region('europe-west1').
firestore

I was only missing a dot (.) before "firestore". Thanks @Jason Berryman for pointing it out!

Sign up to request clarification or add additional context in comments.

Comments

3

For v2: https://firebase.google.com/docs/functions/2nd-gen-upgrade#set_runtime_options

import {onDocumentCreated} from "firebase-functions/v2/firestore";
import {setGlobalOptions} from "firebase-functions/v2";
// locate all functions closest to users
setGlobalOptions({region: "us-west2"});
export const userCreated =
  onDocumentCreated("users/{userId}", (event) => { ... });

Comments

0

For firebase v2 gen cloud functions you can use the below style.

exports.yourapi = onRequest({ region: "us-central1" }, expressjscode);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.