Skip to content

Commit b6f1b10

Browse files
committed
Pass in preferRest to initializeFirestore
This seems to be the recommended technique: firebase/firebase-admin-node#1901 (comment)
1 parent 000ae01 commit b6f1b10

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/firebase.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { initializeApp, cert } from 'firebase-admin/app';
2-
import { getFirestore } from 'firebase-admin/firestore';
2+
import {
3+
getFirestore,
4+
initializeFirestore,
5+
} from 'firebase-admin/firestore';
36

47
// The service account key determines which Firebase project we're using.
58

@@ -12,15 +15,16 @@ const app = initializeApp(
1215
'ltijs-firestore', // Provide a named instance so multiple apps can be initialized: https://github.com/examind-ai/ltijs-firestore/issues/3
1316
);
1417

15-
const db = getFirestore(app);
16-
17-
db.settings({
18-
ignoreUndefinedProperties: true,
18+
const db = initializeFirestore(app, {
1919
// Faster cold starts by using REST (instead of gRPC) where possible: https://github.com/firebase/firebase-admin-node/pull/1901
2020
// As of 2023-07-06, the only operation that requires gRPC is onSnapshot(), which we don't use on the server: https://firebase.google.com/docs/reference/admin/node/firebase-admin.firestore.firestoresettings
2121
// Cold start issue tracker: https://issuetracker.google.com/issues/158014637#comment212
2222
// Disable `preferRest` when running with emulator b/c it causes unit tests to time out on Linux and macOS: https://github.com/firebase/firebase-admin-node/issues/2016#issuecomment-1624775019
2323
preferRest: !process.env.FIRESTORE_EMULATOR_HOST,
2424
});
2525

26+
db.settings({
27+
ignoreUndefinedProperties: true,
28+
});
29+
2630
export { db };

0 commit comments

Comments
 (0)