0

I have created firebase cloud functions using typescript and express. When i write routing in index.ts(working code)and deployed on cloud it's working. When I use express.Route() and then try to deploy functions it is giving error.

Working: index.js -

const app = express();
import * as enquiryService from './modules/enquiry/enquiry.service';
app.post('/enquiry/subscriber', enquiryService.saveSubscriber);
app.post('/enquiry/contact-us', enquiryService.saveContactUs);
export const api = functions.region('asia-northeast1').https.onRequest(app);

Below is index js modified code using express.Route() but not working. while deploying using "firebase deploy --only functions" it is giving me an error: "functions[api(asia-northeast1)]: Deployment error. Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs"

const app = express();
app.use(cors({ origin: '*' }));

import { enquiryRouter } from './modules/enquiry/enquiry.routes'
app.use("/enquiry", enquiryRouter);
export const api = functions.region('asia-northeast1').https.onRequest(app);

Here enquiryRoutes is declared in enquiry.routes.ts

import express from 'express';
export const enquiryRouter = express.Router();
  • "Not working" is not enough information. Please edit the question to explain specifically what isn't working the way you expect. Include any error messages and expected behavior. Your second code sample also looks incomplete, as we can't see what `enquiryRouter` is. I suggest also reading about how to create a [minimal, complete example](https://stackoverflow.com/help/minimal-reproducible-example) that anyone can use to reproduce the issue. – Doug Stevenson Aug 15 '20 at 15:32
  • an answer for this can be [found here](https://stackoverflow.com/questions/62843260/firebase-error-function-failed-on-loading-user-code-node-js) – Methkal Khalawi Aug 18 '20 at 09:36

0 Answers0