GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ishowta/firebase-functions-middleware

BranchesTags
Open more actions menu

Latest commit

 

History

35 Commits
35 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.vscode
.vscode
 
 
src
src
 
 
test
test
 
 
.eslintrc.js
.eslintrc.js
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
jest.config.js
jest.config.js
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
tsup.config.ts
tsup.config.ts
 
 

Repository files navigation

firebase functions middleware

functions v1 thin wrapper for append middlewares

how to use

import {
    Functions,
    parameterLogger,
    timeoutLogger,
    idempotenceGuarantor
} from 'firebase-functions-middleware'
import { getFirestore, initializeFirestore } from 'firebase-admin/firestore';
import { getApps, initializeApp } from 'firebase-admin/app';

if (getApps().length === 0) {
    const firebase = initializeApp();
    initializeFirestore(firebase);
}

const app = new Functions()
app.use(parameterLogger())
app.use(idempotenceGuarantor(getFirestore))
app.use(timeoutLogger())
app.use(({ functionType, options, parameters, next }) => {
    switch (functionType) {
        case 'https.onCall': {
            const [data, context] = parameters;
            // ...
            return next(data, context);
        }
        default:
            return next(...parameters);
    }
});
app.useDeployment(({ options }) => ({
    // for reduce cold start latency
    memory: '1GB',
    ...options,
}));

export const functions = app.builder
import { functions } from '../functions'

export const helloWorld = functions().https.onCall(() => {
    return "Hello world!"
})

parameterLogger

Logging data, contexts and response.

Note:

  • Some data will be filtered
  • Sensitive data may be displayed
functions.use(parameterLogger({
    target: {
        data: true,
        contexts: true,
        response: true
    },
    level: "DEBUG"
}))

idempotenceGuarantor

For functions running at least once, use firestore to achieve exactly once.

functions.use(idempotenceGuarantor({
    firestoreCollectionName: "events" // default
}))

timeoutLogger

Report an error before timeout.

functions.use(timeoutLogger({
    timing: (timeout) => timeout * 0.9 // default
}))

About

No description, website, or topics provided.

Resources

Readme
MIT license
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

Generated from ishowta/my-ts-lib-template
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.