0.1.16 • Published 4 years ago
@inpassor/firebase-application v0.1.16
Firebase application
This library is a handy wrapper for @inpassor/node-server.
It provides a single function firebaseApplication creating a Firebase Cloud function:
firebaseApplication: (
getConfig: ServerConfig | Promise<ServerConfig>,
runtimeOptions?: RuntimeOptions,
) => HttpsFunction
Installation
npm install @inpassor/firebase-application --save
Usage
import { firebaseApplication, Component, ServerConfig } from '@inpassor/firebase-application';
class DemoComponent extends Component {
public get(): void {
console.log(this.request.params);
// You can use here:
// this.app.firebaseApp
// this.app.firestore
this.send(200, 'This is the DemoComponent GET action');
}
}
const config: ServerConfig = {
headers: {
'Access-Control-Allow-Methods': 'OPTIONS, GET',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Headers': 'content-type, authorization',
},
sameOrigin: true,
routes: [
{
path: 'demo</arg|?>',
component: DemoComponent,
},
],
};
export const firebaseFunction = firebaseApplication(config, {
timeoutSeconds: 10,
memory: '128MB',
});
Asynchronous Server config
import { firebaseApplication, ServerConfig } from '@inpassor/firebase-application';
// Some asynchronous get config function
const getConfig = (): Promise<ServerConfig> => {
const config: ServerConfig = {}; // define your own ServerConfig here
return Promise.resolve(config);
};
export const firebaseFunction = firebaseApplication(getConfig(), {
timeoutSeconds: 10,
memory: '128MB',
});