fireproof-storage / fireproof

Realtime database, runs anywhere. Install Fireproof in your front-end app or edge function, and sync data via any backend.
https://fireproof.storage
Other
219 stars 16 forks source link

document how to run on edge functions with remote storage #86

Open jchris opened 4 months ago

jchris commented 4 months ago

https://github.com/fireproof-storage/fireproof/pull/83/files#r1476859216

import { type Database, fireproof } from 'use-fireproof'
import { makeStores, ConnectS3 } from '@fireproof/connect'
import { ConnectPartyKit } from '@fireproof/partykit'

const dbs = new Map<string, Database>()

export function myFireproof(name: string, partyHost?: string) {
  if (dbs.has(name)) {
    return dbs.get(name) as Database
  }
  const s3conf = {
    upload: 'https://04rvvth2b4.execute-api.us-east-2.amazonaws.com/uploads',
    download: 'https://sam-app-s3uploadbucket-e6rv1dj2kydh.s3.us-east-2.amazonaws.com'
  }
  const s3conn = new ConnectS3(s3conf.upload, s3conf.download)
  const partyConn = new ConnectPartyKit({ name, host: partyHost || 'http://localhost:1999' })

  const store = makeStores(s3conn, partyConn)

  const db = fireproof(name, { store })
  dbs.set(name, db)
  return db
}
jchris commented 4 months ago

merged here https://github.com/fireproof-storage/fireproof/pull/83

meghansinnott commented 4 months ago

Another one https://github.com/fireproof-storage/firehouse-chat/blob/bc8cf00df8cb242456ddef3ffd84bea24faf7fe3/src/server.ts#L12