Skip to main content

Firebase

tip

Don't know what a handler is? See the Architecture section.

Requirements

First, install the types for this adapter:

npm i --save firebase-functions firebase-admin

V1 and V2

If you want to use Firebase Functions V1, use HttpFirebaseHandler.

But if you want to add support for V2, then use HttpFirebaseV2Handler.

Integrating with Http Events

To use, you can import HttpFirebaseV2Handler and call the method setHandler, as per the code below:

index.ts
import { ServerlessAdapter } from '@h4ad/serverless-adapter';
import { DummyAdapter } from '@h4ad/serverless-adapter/adapters/dummy';
import { HttpFirebaseV2Handler } from '@h4ad/serverless-adapter/handlers/firebase';
import { DummyResolver } from '@h4ad/serverless-adapter/resolvers/dummy';
import app from './app';

export const helloWorld = ServerlessAdapter.new(app)
.setHandler(new HttpFirebaseV2Handler({
// you can pass custom properties here, like: concurrency.
}))
.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 HttpFirebaseV2Handler())
.setResolver(new DummyResolver())
// choose the framework of your app
// .setFramework(new ExpressFramework())
.addAdapter(new DummyAdapter())
.build();
About Resolver and Adapter

You should use DummyResolver and DummyAdapter because it's a requirement for the library, but HttpFirebaseV2Handler 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.

Examples

You can see examples of how to use here.