@@ -11,6 +11,19 @@ export default async function (session) {
1111 firestoreService . settings ( < %= serialize ( serviceOptions . settings ) % > )
1212 < % } % >
1313
14+ < % /* Uses emulator, if emulatorPort is set. */ % >
15+ < % if ( [ 'string' , 'number' ] . includes ( typeof serviceOptions . emulatorPort ) ) { % >
16+ < % const emulatorHost =
17+ typeof serviceOptions . emulatorHost === 'string'
18+ ? serviceOptions . emulatorHost
19+ : 'localhost'
20+ % >
21+ // If statement fixes Issue #390, only runs useEmulator when not yet called (relevant on server)
22+ if ( process . client || firestoreService . _delegate . _settings . host === 'firestore.googleapis.com' ) {
23+ firestoreService . useEmulator ( '<%= `${emulatorHost}` %>' , < %= `${ serviceOptions . emulatorPort } ` % > )
24+ }
25+ < % } % >
26+
1427 < % if ( serviceOptions . enablePersistence ) { % >
1528 // persistence should only be enabled client side
1629 if ( process . client ) {
@@ -27,18 +40,5 @@ export default async function (session) {
2740 }
2841 < % } % >
2942
30- < % /* Uses emulator, if emulatorPort is set. */ % >
31- < % if ( [ 'string' , 'number' ] . includes ( typeof serviceOptions . emulatorPort ) ) { % >
32- < % const emulatorHost =
33- typeof serviceOptions . emulatorHost === 'string'
34- ? serviceOptions . emulatorHost
35- : 'localhost'
36- % >
37- // If statement fixes Issue #390, only runs useEmulator when not yet called (relevant on server)
38- if ( process . client || firestoreService . _delegate . _settings . host === 'firestore.googleapis.com' ) {
39- firestoreService . useEmulator ( '<%= `${emulatorHost}` %>' , < %= `${ serviceOptions . emulatorPort } ` % > )
40- }
41- < % } % >
42-
4343 return firestoreService
4444}
0 commit comments