firebase / firebase/firebase-admin-node
[FR] Dedicated initializer function for connecting to the Firebase emulator suite
- 主要语言
- TypeScript
- 星标
- 1.7k
- 派生
- 419
- 平均合并
- 3 天 10 小时
- 30 天内合并 PR
- 16
描述
The use case involves use of two initialized instances of FirebaseApp, one for the emulator and another for an actual project. Specifically, it's desirable to programmatically copy data from one to the other without having to export then import separately.
Currently, the Admin SDK requires that an env var is set with host and port in order to connect to the emulator. This is unnecessarily complex when it comes time to init the app. For example, using Auth and Firestore together (and potentially more products) requires code like this:
```js
import { initializeApp } from "firebase-admin/app"
import { getAuth } from "firebase-admin/auth"
import { getFirestore } from "firebase-admin/firestore"
export const remote = initializeApp()
export const remoteAuth = getAuth(remote)
export const remoteFirestore = getFirestore(remote)
process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080'
export const local = initializeApp(undefined, "local")
export const localAuth = getFirestore(local)
export const localFirestore = getFirestore(local)
delete process.env.FIRESTORE_EMULATOR_HOST
```
The use of the temporary env var is clunky here, and it would be more straightforward if there was a dedicated function that allowed the caller to pass the host and port instead:
```js
const host, port = ...
export const local = initializeEmulatorApp(host, port, "local")
export const localAuth = getFirestore(local)
export const localFirestore = getFirestore(local)
```
Either that, or something similar to the way the web and mobile clients work for connecting to the emulator.
贡献指南
调研方向
首先阅读 Admin SDK 的入口点 initializeApp、getAuth 和 getFirestore,以及当前对 FIRESTORE_EMULATOR_HOST 的处理方式。将所请求的 emulator 初始化方式与现有的 Web 和 mobile 客户端方案进行比较。在不使用临时环境变量的情况下支持 emulator 和远程 FirebaseApp 实例分离,并包括 Auth 和 Firestore 的使用,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- node.js, typescript
- 领域
- api, backend
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100