Recently, I faced an issue while deploying a TypeScript project to firebase-functions where all the code was stored in index.ts. Initially, everything worked fine but when I decided to refactor my code, I discovered that firebase was not able to recognize routes specified in files outside of index.ts (or the file containing functions.https.onRequest()
).
Below is a reproduction of the problem:
//index.ts
import * as functions from 'firebase-functions';
import * as express from "express";
export const expressApp = express();
expressApp.get("/hi", (req, res)=> {
res.send("hi");
})
export const TestApp = functions.https.onRequest(expressApp);
An external file in the same directory adding the "/hello"
route.
//external.ts
import { expressApp } from "./index";
expressApp.get("/hello", (req, res)=> {
res.send("hello")
})
After deploying with firebase-deploy
, the "/hi"
route in index.ts works correctly, but the "/hello"
route in external.ts returns an error (Cannot GET /hello
).
My assumption is that the TestApp is being exported to firebase-functions before it's accessed by any external files.
Is there a workaround for this issue in a TypeScript project?