firebase部署错误,运行node.js 16函数应用程序(us-central1)似乎面临问题
我将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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论