firebase部署错误,运行node.js 16函数应用程序(us-central1)似乎面临问题

发布于 2025-01-23 00:33:45 字数 2081 浏览 0 评论 0原文

我将Express应用程序部署到Firebase功能上。但是在执行功能时会收到错误:创建node.js 16函数应用程序(us-central1)...

这是我的ExpressJS示例下的“ functions”文件夹。我不太确定正在发生的事情

const express = require('express')
const firebasefunctions = require('firebase-functions')
const cors = require('cors')
const dotenv = require('dotenv');
const fs = require('fs');
dotenv.config();


const app = express()
const port = process.env.DB_PORT

app.use(cors())
app.use(express.json())
app.use(express.urlencoded())

const knex = require('knex')({
    client: 'pg',
    connection: {
      host : process.env.DB_HOST,
      port : process.env.DB_DO_PORT,
      user : process.env.DB_USERNAME,
      password : process.env.DB_PASSWORD,
      database : process.env.DB_DO,
      ssl: {
        ca: fs.readFileSync('./ca-certificate.crt').toString()
      }
    }
});

app.get('/data', (req, res) => {
    knex.select().table('tablename')
    .then(response => res.json(response))
    .catch(console.log)
    
})

app.post('/update', (req, res) => {
    
    console.log(req.body)
    req.body.forEach(item => {
        knex('tablename')
        .where('number', '=', item)
        .increment({
            occurence: 1
        })
        .catch(console.log)
    })
    res.json("Success")
})

exports.app = firebasefunctions.https.onRequest(app)

和包装

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "16"
  },
  "main": "index.js",
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^16.0.0",
    "express": "^4.17.3",
    "firebase-admin": "^10.0.2",
    "firebase-functions": "^3.18.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

“

I am deploying express application to firebase Functions. But receiving error when it's doing functions: creating Node.js 16 function app (us-central1)...

Here are my ExpressJS sample under "Functions" folder. I not quite sure what is happening

const express = require('express')
const firebasefunctions = require('firebase-functions')
const cors = require('cors')
const dotenv = require('dotenv');
const fs = require('fs');
dotenv.config();


const app = express()
const port = process.env.DB_PORT

app.use(cors())
app.use(express.json())
app.use(express.urlencoded())

const knex = require('knex')({
    client: 'pg',
    connection: {
      host : process.env.DB_HOST,
      port : process.env.DB_DO_PORT,
      user : process.env.DB_USERNAME,
      password : process.env.DB_PASSWORD,
      database : process.env.DB_DO,
      ssl: {
        ca: fs.readFileSync('./ca-certificate.crt').toString()
      }
    }
});

app.get('/data', (req, res) => {
    knex.select().table('tablename')
    .then(response => res.json(response))
    .catch(console.log)
    
})

app.post('/update', (req, res) => {
    
    console.log(req.body)
    req.body.forEach(item => {
        knex('tablename')
        .where('number', '=', item)
        .increment({
            occurence: 1
        })
        .catch(console.log)
    })
    res.json("Success")
})

exports.app = firebasefunctions.https.onRequest(app)

And also the package.json under "Functions"

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "16"
  },
  "main": "index.js",
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^16.0.0",
    "express": "^4.17.3",
    "firebase-admin": "^10.0.2",
    "firebase-functions": "^3.18.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

The error debug looks like this
Firebase-debug-log

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文