Skip to content

Commit

Permalink
docs(firebase): added documentation to use firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Jul 17, 2022
1 parent 9664f6b commit 2f4dbcf
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 9 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
"trpc",
"azure",
"azure-functions",
"http-trigger-v4"
"http-trigger-v4",
"firebase",
"firebase-functions",
"firebase-http-events"
],
"bugs": {
"url": "https://github.com/H4ad/serverless-adapter/issues"
Expand Down
1 change: 1 addition & 0 deletions src/index.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './frameworks/lazy';
export * from './frameworks/trpc';
export * from './handlers/azure';
export * from './handlers/default';
export * from './handlers/firebase';
export * from './handlers/huawei';
export * from './network';
export * from './resolvers/aws-context';
Expand Down
4 changes: 1 addition & 3 deletions www/docs/main/handlers/default.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ To use, you can import and call the method [setHandler](../../api/ServerlessAdap
```ts title="index.ts"
import { ServerlessAdapter } from '@h4ad/serverless-adapter';
import { DefaultHandler } from '@h4ad/serverless-adapter/lib/handlers/default';
import app from './app';

const express = require('express');

const app = express();
export const handler = ServerlessAdapter.new(app)
.setHandler(new DefaultHandler())
// continue to set the other options here.
Expand Down
67 changes: 67 additions & 0 deletions www/docs/main/handlers/firebase.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Firebase
position: 3
description: See more about how to integrate with Firebase Functions.
---

:::tip

Don't know what a handler is? See the [Architecture](../architecture#handler) section.

:::

## Requirements

First, install the types for this adapter:

```bash
npm i --save firebase-functions firebase-admin
```

## Integrating with Http Events

To use, you can import [HttpFirebaseHandler](../../api/Handlers/HttpFirebaseHandler) and call the method [setHandler](../../api/ServerlessAdapter#method-sethandler), as per the code below:

```ts title="index.ts"
import { ServerlessAdapter } from '@h4ad/serverless-adapter';
import { DummyAdapter } from '@h4ad/serverless-adapter/lib/adapters/dummy';
import { HttpFirebaseHandler } from '@h4ad/serverless-adapter/lib/handlers/firebase';
import { DummyResolver } from '@h4ad/serverless-adapter/lib/resolvers/dummy';
import app from './app';

export const helloWorld = ServerlessAdapter.new(app)
.setHandler(new HttpFirebaseHandler())
.setResolver(new DummyResolver())
// choose the framework of your app
// .setFramework(new ExpressFramework())
.addAdapter(new DummyAdapter())
.build();

// you can export more than one if you want
export const test = ServerlessAdapter.new(app)
.setHandler(new HttpFirebaseHandler())
.setResolver(new DummyResolver())
// choose the framework of your app
// .setFramework(new ExpressFramework())
.addAdapter(new DummyAdapter())
.build();
```

:::info About Resolver and Adapter

You should use DummyResolver and DummyAdapter because it's a requirement for the library, but HttpFirebaseHandler doesn't do anything with them,
so you use those dummy versions just to satisfy the library requirements.

:::

## What about Cron, Pub/Sub, etc?

I could not think yet in an API to handle those cases well,
so currently I didn't add support to these type of Firebase Functions.

If you have some idea about a design for those APIs, [create an issue](https://github.com/H4ad/serverless-adapter/issues/new/choose).

## Examples

You can see examples of how to use [here](https://github.com/H4ad/serverless-adapter-examples).

2 changes: 1 addition & 1 deletion www/docs/main/handlers/huawei.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Huawei
position: 3
position: 4
description: See more about how to integrate with Huawei.
---

Expand Down
3 changes: 2 additions & 1 deletion www/docs/main/intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ We support these event sources:
- Azure
- [Http Trigger V4](https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-javascript) by using ([HttpTriggerV4Adapter](./adapters/azure/http-trigger-v4)).
- Firebase
- The support is coming soon.
- [Http Events](https://firebase.google.com/docs/functions/http-events) using ([HttpFirebaseHandler](./handlers/firebase)).
- GCP
- The support is coming soon.

Expand All @@ -82,6 +82,7 @@ We support these handlers:

- Azure by using ([AzureHandler](./handlers/azure))
- Default by using ([DefaultHandler](./handlers/default))
- Firebase by using ([HttpFirebaseHandler](./handlers/firebase))
- Huawei by using ([HttpHuaweiHandler](./handlers/huawei#http-function)) and ([EventHuaweiHandler](./handlers/huawei#event-function))

## Why you create this library?
Expand Down
11 changes: 8 additions & 3 deletions www/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ const sidebars = {
link: {
type: 'generated-index',
},
collapsed: true,
items: ['main/handlers/azure', 'main/handlers/default', 'main/handlers/huawei'],
collapsed: false,
items: [
{
type: 'autogenerated',
dirName: 'main/handlers',
},
],
},
{
type: 'category',
Expand All @@ -113,7 +118,7 @@ const sidebars = {
link: {
type: 'generated-index',
},
collapsed: false,
collapsed: true,
items: [
'main/frameworks/express',
'main/frameworks/fastify',
Expand Down

0 comments on commit 2f4dbcf

Please sign in to comment.