Quantcast
Channel: Google Cloud Platform その1 Advent Calendarの記事 - Qiita
Viewing all articles
Browse latest Browse all 23

TypeScript で Google Cloud Functions やりたい人向けのテンプレートをつくった

$
0
0

TypeScriptでCloud Functionsをやるときに毎回同じようなことを書いていたので、テンプレートを作りました。※Firebaseコマンドで Firebase Functions をやるときは JavaScriptかTypeScriptか選択することができます。

リポジトリ

https://github.com/flatfisher/cloud-functions-typescript-template

オススメの設定や何か問題などあればIssueやプルリクエストをいただけると嬉しいです:smile:

下準備

configを変更します。 runtimeの違いによって動作しない機能もございますので 、詳しくはドキュメントをご参照ください。

package.json
"config": {
    "function_name": "helloWorld",
    "region": "リージョンをいれる 例:asia-northeast1",
    "gcp_project": "GCPのプロジェクトIDをいれる",
    "runtime": "ランタイムを指定 例:nodejs8"
  },

Lint

$ npm run lint

Build

functions/src/ に Node.js のプロジェクトがビルドされます

$ npm run build

Test

$ npm install -g mocha // mochaがインストールされていればスキップ

$ npm run test

  Hello function
    ✓ Get 200 response

  1 passing (31ms)

Deploy

Cloud Functionsにデプロイします

$ npm run deploy --prefix functions/src/

リクエスト

デプロイ後に表示されるhttpsTriggerURLにリクエストしHello Worldが表示されればデプロイに成功しています。

$ curl https://asia-northeast1-foo.cloudfunctions.net/helloWorld
$ Hello World

Viewing all articles
Browse latest Browse all 23

Trending Articles