Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
Firebase cloud function https.onRequest inside a wrapper function

I am using Firebase cloud functions (node.js) for my app and I want to create a shared wrapper for all of my endpoints that will handle errors and have some checks.

Is it possible to create a wrapper function for the cloud functions and then expose it as a new endpoint?

Example:

// normal function that works
const helloWorld = functions.https.onRequest((req, res) => {
    functions.logger.log("hello world!");
    return res.end();
})

// the wrapper function that handles errors and shared logic
const functionsWrapper = async ({allowedMethods, handler}) =>
    functions.https.onRequest(async (req, res) => {
            try {
                if (allowedMethods) {
                    if (!allowedMethods.includes(req.method.toLowerCase())) {
                        return res.status(405).end();
                    }
                }
                const result = await handler;
                return res.json(result);
            } catch (error) {
                //handling errors here
            }
        }
    );

// the function I want to wrap and then expose as an endpoint
const anotherFunc = functionsWrapper({
    allowedMethods: ['get'],
    async handler() {
        return {message: 'I am inside functionsWrapper'}
    }
})

// exposing the functions
module.exports = {
    helloWorld, // helloWorld can be called and gets an endpoint
    anotherFunc // anotherFunc does not get an endpoint
}

I think that Firebase finds where functions.https.onRequest is being exported and then exposes it as an endpoint but how can I expose 'anotherFunc'?

Or in short how to expose:

const endpoint = () => functions.htpps.onRequest((req, res) => {})

Thanks!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda