Currently, I have successfully deployed a front-end React UI project on Firebase. However, the back-end Node.js/Express app that I am attempting to deploy using Firebase functions is only functioning locally. The logs indicate an error in the user code, but I'm unsure where to begin troubleshooting since it works fine on my local machine. As I am relatively new to working with technologies like Firebase, any assistance would be highly valued. I've tried various fixes from online resources, which have brought me this far. Please find the relevant code snippets below:
root - functions - index.js
const functions = require("firebase-functions");
const express = require("express");
const cors = require("cors");
const expressApp = express();
const serviceApp = require("../src/app");
expressApp.use(cors());
expressApp.use("/", serviceApp);
exports.app = functions.https.onRequest(expressApp);
root - firebase.json
{
"functions": {
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"source": "functions"
},
"hosting": {
"site": "gys-be-test",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites" : [{"source" : "**", "function" : "app"}]
}
}
root-src-app.js
const path = require("path");
require("dotenv").config({ path: path.join(__dirname, "..", ".env") });
const express = require("express");
const cors = require("cors");
const errorHandler = require("./errors/errorHandler");
const notFound = require("./errors/notFound");
const resourcesRouter = require("./Resources/resources.router");
const contactsRouter = require("./Contacts/contacts.router");
const postsRouter = require("./Posts/posts.router");
const usersRouter = require("./Users/users.router");
const promptsRouter = require("./Prompts/prompts.router");
const eventsRouter = require("./Events/events.router");
const app = express();
app.use(cors());
app.use(express.json());
// Routes setup
app.use("/users", usersRouter);
app.use("/posts", postsRouter);
app.use("/prompts", promptsRouter);
app.use("/events", eventsRouter);
app.use("/resources", resourcesRouter);
app.use("/contacts", contactsRouter);
// Error handling middleware
app.use(notFound);
app.use(errorHandler);
module.exports = app;
root-src-server.js
const { PORT = 5001 } = process.env;
const app = require("./app");
const knex = require("./db/connection");
knex.migrate
.latest()
.then((migrations) => {
console.log("migrations", migrations);
app.listen(PORT, listener);
})
.catch((error) => {
console.error(error);
knex.destroy();
});
function listener() {
console.log(`Listening on Port ${PORT}!`);
}
A snippet from the Firebase debug log:
[info] Functions deploy had errors with the following functions:
app(us-central1)
[debug] [2022-09-04T20:22:06.986Z] Not printing URL for HTTPS function. Typically this means it didn't match a filter or we failed deployment
...
I would greatly appreciate any assistance. Thank you!