Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The way of truly serverless application

miup
November 21, 2017

The way of truly serverless application

Firebase.yebisu #1

miup

November 21, 2017
Tweet

More Decks by miup

Other Decks in Programming

Transcript

  1. CloudFunctions • HTTP ΍ DB ΁ͷมߋΛϑοΫʹಈ࡞͢Δ Node.js ؀ڥ • ΋ͪΖΜ

    TypeScript Ͱ΋ॻ͚Δ • ֎෦ API Λୟ͚Δ • Push ௨஌ૹΕΔ
  2. Write functions.database.ref(‘path/to/user/{userID}').onCreate(async event => { let userID = event.params!.userID let

    firUser = await admin.database() .ref(`path/to/user/${userID}`) .once(‘value').then(snap => snap.val()) let userIndex = algolia.initIndex('user') let user = new User(userID, firUser) return userIndex.addObject(user) // send FCM for callback }) ref: https://qiita.com/star__hoshi/items/6ee9d1413a34ca5849eb
  3. Request struct AlgoliaFeedRequest: AlgoliaRequestProtocol { typealias HitType = Algolia.Feed var

    indexName: String { return "feed" } var query: AlgentQuery { let query = AlgentQuery() return query } }
  4. Read // search from algolia using Algent // Result<Response<Response<Request.HitType>, Error>

    Algent.shared.search(request: AlgoliaFeedRequest()) Firebase.Post.databaseRef .child(feed.objectID) .child(“likes/count") .observe(.value) { [weak self] snapshot in if snapshot.exists() { self?.likeCountString.value = "\(snapshot.value as? Int)" } else { self?.likeCountString.value = "0" } }
  5. Sample • SNS ͬΆ͍΍ͭ • Feed ͱ User ͸ Algolia

    ͔Βݕࡧ • ͍͍Ͷʂ΍౤ߘ਺ͳͲͷมಈ͢Δ஋ͷΈΛ RealtimeDB͔ΒObserve • Silent Push ͔Βߋ৽͸ະ࣮૷
  6. Q&A