LoginSignup
3
1

More than 5 years have passed since last update.

ローカルでCloud FunctionsのHTTPS関数を実行する

Last updated at Posted at 2017-12-06

修正 > デプロイを繰り返すのはツライので、ローカルで実行できる環境を整えたときのメモ

Firebase CLIインストール

参考
* Testing Functions Locally with the Cloud Functions Shell
* Firebase Documentation - ローカルでの関数の実行
* npm - request


上記のブログなどを参考に、Firebase CLIのバージョンをv3.11.0に上げてコマンドを試した。

experimental:functions:shell [options]     launch full Node shell with emulated functions

 
実行したところエラー出たので言われるがままv6.9.1にして再実行

functions: Cannot start emulator. Please use Node version v6.9.1, you have v7.3.0

 
またエラーとりあえずv6.11.5にして試してみる…

Node.js v6.11.x or greater is required to run the Emulator!

 
やっとローカル実行できるようになった

$ sudo firebase experimental:functions:shell
i  functions: Preparing to emulate functions.
✔  functions: test
firebase >

HTTPS関数の実行

実行したかったのはHTTPS関数だったので、こちらを参考に。
Firebase Documentation - HTTPS 関数を呼び出す
 
なので、testというファンクションを実行する場合はこうなる。

test.get()

  
下記のようにGETパラメータだけ付けて実行したいのだが…例の一覧には記載はなく。

https://us-central1-xxxxxxx.cloudfunctions.net/test?key=value

 

シェルで HTTPS 関数を呼び出す場合、使用方法は request NPM モジュールと同じですが

と書いてあったので、次のように実行したら思ったように動作した。

test.get({qs: {key: 'value'}})
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1