Skip to content

Commit

Permalink
initial, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
samcorcos committed Feb 23, 2019
0 parents commit b17b34d
Show file tree
Hide file tree
Showing 5 changed files with 1,907 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Firestore REST

Due to an issue with gRPC, any request that involves Firestore in conjunction with Firebase Functions with take 5-10 seconds to respond after a deploy.

For more information about this particular issue, see [this ticket](https://github.com/googleapis/nodejs-firestore/issues/528).

As of February 2019, if you want your Firestore requests to respond in less than 5-10 seconds after a deploy, you have to use the REST API provided by `googleapis`.

This package wraps the [`googleapis`](https://github.com/googleapis/google-api-nodejs-client/) class for [Firestore](https://apis-nodejs.firebaseapp.com/firestore/classes/Firestore.html) in a way that is easier to use.

Hopefully, when [this ticket](https://github.com/googleapis/gax-nodejs/issues/401) is resolved, this package will no longer be necessary, but according to Google support, this might be a persistent issue until late 2019. Until then, you should be able to use this package without much downside.

https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents

## Installation

```
npm i --save firestore-rest
```

## Usage

When initializing `firebase-admin`, initialize and export `db` as well, as seen below.

```js
const admin = require('firebase-admin')
const Firestore = require('firestore-rest')

var serviceAccount = require('../path/to/credentials.json')

admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://<your app>.firebaseio.com'
})

// const db = admin.firestore() <= this is the old way to do it
const db = new Firestore()

module.exports = {
admin,
db
}
```

Then you can use the function the same way you would otherwise, as this package transforms the results to be backwards-compatible. For example:

```js
const getSome = async () => {
try {
const response = await db.collection('users').doc('12312312421321').get()
console.log(response)
} catch (err) {
console.error(err)
}
}
```
Empty file added index.js
Empty file.
Loading

0 comments on commit b17b34d

Please sign in to comment.