|
|
| (同じ利用者による、間の13版が非表示) |
| 行1: |
行1: |
| − | ==CloudFunctionsとは==
| + | [[Gcp/Firebase/CloudFunctions/基本]] |
| − | *関数処理をしてくれるもの。awsのlamdaと同じ。
| + | |
| − | *nodeで動く
| + | |
| | | | |
| − | ==CloudFunction準備==
| + | [[Gcp/Firebase/CloudFunctions/request]] |
| − | ===nvmインストール===
| + | |
| − | [[Javascript/nodejs/インストール/nvm]] [ショートカット] | + | |
| | | | |
| − | ===firebaseログイン===
| + | [[Gcp/Firebase/CloudFunctions/nodeバージョン]] |
| − | $ npm install -g firebase-tools
| + | |
| − | $ firebase --version
| + | |
| − | 6.10.0
| + | |
| − | $ firebase login
| + | |
| − | ブラウザが開くので、firebaseコンソールに繋がるgoogleアカウントでログインする。
| + | |
| | | | |
| − | ===firebaseログアウト===
| + | [[Gcp/Firebase/CloudFunctions/cron]] |
| − | $ firebase logout
| + | |
| | | | |
| − | ==functionsを新規作成==
| + | [[Gcp/Firebase/CloudFunctions/カスタムクラス]] |
| − | $ firebase init functions
| + | |
| − | ? What language would you like to use to write Cloud Functions? JavaScript
| + | |
| − | ? Do you want to use ESLint to catch probable bugs and enforce style? No
| + | |
| − | ✔ Wrote functions/package.json
| + | |
| − | ✔ Wrote functions/index.js
| + | |
| − | ✔ Wrote functions/.gitignore
| + | |
| − | ? Do you want to install dependencies with npm now? Yes
| + | |
| | | | |
| − | #プロジェクトを選択
| + | [[Gcp/Firebase/CloudFunctions/外部ライブラリ]] |
| − | #JavaScriptとTypeScriptを選択、とりあえずJavaScriptを選択
| + | |
| − | #ESLintはデフォルトoffだったので、offで作成
| + | |
| − | #npmの依存パッケージはデフォルトyesだったので、yesで作成
| + | |
| | | | |
| − | ==スクリプト修正==
| + | [[Gcp/Firebase/CloudFunctions/Realtimedatabaseトリガー]] |
| − | functions/index.js
| + | |
| − | exports.helloWorld = functions.https.onRequest((request, response) => {
| + | |
| − | response.send("Hello from Firebase!");
| + | |
| − | });
| + | |
| − | コメントを外す
| + | |
| | | | |
| − | ==deploy==
| + | [[Gcp/Firebase/CloudFunctions/Basic認証]] |
| − | $ firebase deploy --only functions
| + | |
| − | ttps://us-central1-unity-xxxxx.cloudfunctions.net/helloWorld
| + | |
| − | メソッドをコメントアウトしたままだと公開用urlは出てこない
| + | |
| − | | + | |
| − | ==httpアクセス==
| + | |
| − | Hello from Firebase!
| + | |
| − | | + | |
| − | 最初のアクセスだけgoogle認証が必要?2回目からは別のブラウザからでも認証画面が出てこなかった。
| + | |
| − | | + | |
| − | ==log==
| + | |
| − | console.log('I am a log entry!');
| + | |
| − | *console.log() INFO ログレベル
| + | |
| − | *console.error() ERROR ログレベル
| + | |
| − | *内部システム DEBUG ログレベル
| + | |
| − | | + | |
| − | 以下のような感じで表示される
| + | |
| − | 時刻arrow_downward レベル 関数 イベント メッセージ
| + | |
| − | 1:57:06.117 午前 info helloWorld I am aa log entry!
| + | |
| − | 1:56:20.007 午前 warning helloWorld2 error2
| + | |
| − | | + | |
| − | \nで改行にできる。ただし、文字列が多い場合のみ
| + | |
| − | | + | |
| − | ===log割り当て制限===
| + | |
| − | https://cloud.google.com/logging/quota-policy
| + | |
| − | | + | |
| − | <pre>
| + | |
| − | ログエントリのサイズ 100 KB*
| + | |
| − | entries.write リクエストのサイズ 5 MB*
| + | |
| − | entries.write API 呼び出しの数 1 プロジェクトあたり 1,000 回/秒
| + | |
| − | entries.list API 呼び出しの数 1 プロジェクトあたり 1 回/秒
| + | |
| − | ログエントリの保持期間 30 日(プレミアム階層)
| + | |
| − | 7 日(基本階層)
| + | |
| − | ユーザー定義のログベースの指標 1 プロジェクトあたり 500 件
| + | |
| − | API からのページトークンの有効期間 24 時間
| + | |
| − | </pre>
| + | |
| − | | + | |
| − | ==Stackdriver Error Reporting にエラーを送信==
| + | |
| − | console.error(new Error('message'));
| + | |
| − | | + | |
| − | 参考:https://cloud.google.com/functions/docs/monitoring/error-reporting?hl=ja
| + | |
| − | | + | |
| − | ==参考==
| + | |
| − | https://devlog.hassaku.blue/2019/03/unity-firebase-firebase.html
| + | |