简体   繁体   English

在 firebase 上部署 react 前端和 express/nodejs 后端

[英]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.

相关问题 如何在前端和后端之间持久化 Firebase Auth state? (Firebase 身份验证 + React + Express) - How to persist the Firebase Auth state between front-end and backend ? (Firebase Auth + React + Express) Firebase 是 react-native 后端 - Firebase are react-native backend 将 react-app 部署到 firebase 主机时出现空白页? - blank page when deploying react-app into firebase hosting? Firebase 托管 NodeJS Express 应用程序不工作,超时很多 - Firebase Hosting NodeJS Express App not working, times out a lot 我如何使用我的 Node/Express 和 Firebase 后端将用户保留在我的 web 应用程序上 - How can i persist users on my web application with my Node/Express and Firebase backend 将 React 项目部署到 Firebase 会导致显示“Firebase 托管设置完成”的窗口 - Deploying React project to Firebase leads to window that says "Firebase Hosting Setup Complete" 每当我尝试使用 Firebase 输入新值时,我的 React JS 前端应用程序就会冻结 - My React JS frontend application freezes whenever I try to input a new value using Firebase 如果我的后端是 firebase firestore,我如何在我的 react js 应用程序中使用 JWT - How do i use JWT in my react js app, if my backend is firebase firestore Vue Firebase、MySQL &amp; Express - Vue Firebase, MySQL & Express 我如何托管使用 firebase 作为其后端的 react crud 应用程序 - how can i host a react crud appliction that uses firebase as its backend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM