My goal is to locally trigger a Firebase Cloud Function using the emulator. However, every time I try, the function returns a 404 Not Found
status code and a response body of Cannot Get
. The function is deployed locally and visible on the UI, but it fails with the above-mentioned errors when accessed.
The function deploys to this endpoint:
http://localhost:5001/project/region/health
and the command I use is: firebase emulators:start --only functions
// app.ts
import * as express from 'express';
import * as functions from 'firebase-functions';
import { router as healthRouter } from './api/utils/router';
const healthApp = express();
healthApp.use('/health', healthRouter);
export = {
health: functions.region('northamerica-northeast1').https.onRequest(healthApp),
};
// router.ts
import { Router } from 'express';
import { health } from './health';
export const router = Router();
router.get('/', health);
// health.ts
import type { Request, Response } from 'firebase-functions';
import * as functions from 'firebase-functions';
export const health = functions.https.onRequest(
(req: Request, res: Response) => {
res.status(200);
}
);
// tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"allowSyntheticDefaultImports": true
},
"compileOnSave": true,
"include": [
"src"
]
}