「Cloud Functions for Firebase」の版間の差分
ナビゲーションに移動
検索に移動
17行目: | 17行目: | ||
===サードパーティのサービスおよび API と統合=== | ===サードパーティのサービスおよび API と統合=== | ||
[[File:GoogleCloudFunctions_UseCase4.png]] | [[File:GoogleCloudFunctions_UseCase4.png]] | ||
+ | ==サンプル== | ||
+ | *https://firebase.google.com/docs/functions/get-started?hl=ja | ||
+ | メッセージをFirestoreに保存する | ||
+ | import * as functions from 'firebase-functions'; | ||
+ | import * as admin from 'firebase-admin'; | ||
+ | admin.initializeApp(); | ||
+ | |||
+ | export const addMessage = functions.https.onRequest((request, response) => { | ||
+ | const original = request.query.text; | ||
+ | admin.firestore().collection("message").add({original: original}).then( | ||
+ | (data) => { | ||
+ | response.json({result: `Message with ID: ${data.id} added.`}); | ||
+ | } | ||
+ | ).catch( | ||
+ | (e) => { | ||
+ | response.json(e); | ||
+ | } | ||
+ | ); | ||
+ | }); |
2020年7月18日 (土) 15:43時点における版
目次
Cloud Functions for Firebase
Firebase | Google Cloud Platform
環境構築
- https://firebase.google.com/docs/functions/get-started?hl=ja
- Cloud Functions for Firebase の開発環境をととのえる
処理
典型的な使用例
関心事が発生したときにユーザーに通知
データベースのサニタイズとメンテナンスを実行
アプリではなくクラウドで集中的なタスクを実行
サードパーティのサービスおよび API と統合
サンプル
メッセージをFirestoreに保存する
import * as functions from 'firebase-functions'; import * as admin from 'firebase-admin'; admin.initializeApp(); export const addMessage = functions.https.onRequest((request, response) => { const original = request.query.text; admin.firestore().collection("message").add({original: original}).then( (data) => { response.json({result: `Message with ID: ${data.id} added.`}); } ).catch( (e) => { response.json(e); } ); });
© 2006 矢木浩人