[英]Deploying react frontend & express/nodejs backend on firebase
I have a project on firebase for a front-end React UI deployed just fine, but the back-end nodejs/express app I am trying to deploy with firebase functions is only working locally.我有一个关于 firebase 的项目,用于前端 React UI 部署得很好,但是我尝试使用 firebase 功能部署的后端 nodejs/express 应用程序只能在本地工作。 Logs say there is an error in the user code but I'm not sure where to even look if it works fine locally.
日志说用户代码中存在错误,但如果它在本地工作正常,我什至不确定在哪里查看。 Might be missing something, still new to using tech like firebase so any help would be appreciated, I tried a few different fixes online and it's gotten me this far haha.
可能会遗漏一些东西,对于使用像 firebase 这样的技术来说仍然是新的,所以任何帮助都将不胜感激,我在网上尝试了一些不同的修复程序,它让我走了这么远哈哈。 Code snippets below
下面的代码片段
root - functions - index.js根 - 函数 - 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根 - 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根-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());
app.use("/users", usersRouter);
app.use("/posts", postsRouter);
app.use("/prompts", promptsRouter);
app.use("/events", eventsRouter);
app.use("/resources", resourcesRouter);
// app.use("/downloads", downloadsRouter);
// app.use("/media", mediaRouter);
app.use("/contacts", contactsRouter);
app.use(notFound);
app.use(errorHandler);
module.exports = app;
root-src-server.js根-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}!`);
}
and a snippet from the firebase debug log以及来自 firebase 调试日志的片段
[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
[info] i functions: cleaning up build files...
[debug] [2022-09-04T20:22:06.988Z] >>> [apiv2][query] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/gys-be-test/locations/us-central1/repositories/gcf-artifacts/packages/app [none]
[debug] [2022-09-04T20:22:06.989Z] >>> [apiv2][query] GET https://us.gcr.io/v2/gys-be-test/gcf/us-central1/tags/list [none]
[debug] [2022-09-04T20:22:07.199Z] <<< [apiv2][status] GET https://us.gcr.io/v2/gys-be-test/gcf/us-central1/tags/list 200
[debug] [2022-09-04T20:22:07.199Z] <<< [apiv2][body] GET https://us.gcr.io/v2/gys-be-test/gcf/us-central1/tags/list {"child":[],"manifest":{},"name":"gys-be-test/gcf/us-central1","tags":[]}
[debug] [2022-09-04T20:22:07.200Z] Could not find image for function projects/gys-be-test/locations/us-central1/functions/app
Any help would be greatly appreciated!!任何帮助将不胜感激!! Thanks!
谢谢!
First of all I'd like to welcome you to StackOverflow.首先,我想欢迎您使用 StackOverflow。
I think it look weird with the exports.app in the first snippet, I personally don't understand why it is not exports.module, can you confirm this is intentional before we continue?我认为第一个片段中的exports.app 看起来很奇怪,我个人不明白为什么它不是exports.module,在我们继续之前你能确认这是故意的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.