Skip to content

Instantly share code, notes, and snippets.

@LeeDDHH
Last active September 21, 2021 01:46
Show Gist options
  • Save LeeDDHH/6215f9b3ac6cd291a790dcb39eff721a to your computer and use it in GitHub Desktop.
Save LeeDDHH/6215f9b3ac6cd291a790dcb39eff721a to your computer and use it in GitHub Desktop.
firebaseのエミュレーター環境を整える

Local Emulator Suite のインストール

  • firebaseプロジェクトの初期化は終えておく
  • firebase init emulators
    • Emulator Suite を設定する
    • 目的のエミュレータを選択し、対応するエミュレータのバイナリ ファイルをダウンロードして、デフォルトが適切でない場合はエミュレータ ポートを設定します。
  • エミュレータがインストールされると、Firebase CLI のバージョンを更新するまで、アップデートのチェックは行われず、追加の自動ダウンロードも行われない

Emulator Suite の構成

  • 必要に応じて、エミュレータのネットワークポートとセキュリティルール定義へのパスをfirebase.jsonファイルで構成できる
    • firebase init emulatorsを実行する
    • firebase.jsonを手動で編集して、エミュレータのポートを変更、セキュリティ ルールの定義へのパスを変更する

ポートの構成

  • 各エミュレータは、希望するデフォルト値でマシン上の異なるポートにバインドされる
エミュレータ デフォルト ポート
Authentication 9099
Emulator Suite UI 4000
Cloud Functions 5001
Realtime Database 9000
Cloud Firestore 8080
Cloud Storage 9199
Firebase Hosting 5000
Pub/Sub 8085

Emulator Hub REST API を使用する

実行中のエミュレータのリストを取得する

  • エミュレータ ハブの /emulators エンドポイントに GET リクエストを送信する
    • curl localhost:4400/emulators
    • 実行中のすべてのエミュレータと、そのホストおよびポートの構成などのリストが含まれるJSONオブジェクトが返される

ローカルでカスタム関数の構成変数を使用する

  • functions ディレクトリ内で .runtimeconfig.json に書き出す
    • firebase functions:config:get > .runtimeconfig.json
    • プロジェクト初期化時に .gitignore として .runtimeconfig.json が入っている

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment