I am currently developing an API with google’s Cloud function, and wanted to know how arrange my Node.js index.ts file so that I can keep my callback functions in separated files while still handling them as POST and “merging” them at a single file using Node.js routing. I tried to follow the examples in this question and the official documentation, but they all implement the callbacks in the main index.ts file, which obviously isn’t the best approach.
My function file helloWorld.ts:
export type Indexable = { [key: string ]: any};
import {onRequest} from "firebase-functions/v2/https";
export const helloWorld = onRequest((request, response) => {
response.send(`<h1>${request.params[0]}</h1>`);
});
index.ts:
import {onRequest} from "firebase-functions/v2/https";
import express = require("express");
import {helloWorld} from "./helloWorld";
const app = express();
app.get("hello", (req, res) => helloWorld(req, res));
exports.events = onRequest(app);
Recognized by Google Cloud Collective
1