Имея разностороннее развертывание моих функций, а также хостинг.
Дело в том, что я заставил их работать независимо в отдельных ветвях, однако ... при попытке интегрировать как хостинг, так и мои облачные функции, кажется, что моя облачная функция не развертывается. Я не получаю никаких ошибок в своем терминале, и когда я нажимаю «функции» в консоли Firebase, это экран по умолчанию, как будто ни одна из функций не развернута.
Это моя база Firebase. json для хостинга + функции развертывания. Хостинг работает здесь, но функции не развертываются
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
},
{
"source": "/api/v1/**",
"function": "webApi"
}
]
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
],
"source": "functions"
}
}
Вот моя база данных. json только с функциями и без хостинга
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/api/v1/**",
"function": "webApi"
}
]
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
],
"source": "functions"
}
}
И вот мои функции /index.js
const functions = require('firebase-functions')
const admin = require('firebase-admin')
const serviceAccount = require('./serviceAccount.json')
const express = require('express')
const bodyParser = require('body-parser')
const _ = require('lodash')
const { getObjectValues } = require('./helper-functions.js')
const json2csv = require('json2csv').parse
admin.initializeApp({
...,
})
const db = admin.firestore()
const app = express()
const main = express()
main.use('/api/v1', app)
main.use(bodyParser.json())
exports.webApi = functions.https.onRequest(main)
app.get('/test', (request, response) => {
response.send('API TEST')
})
app.get('/surveys', (request, response) => {
const surveyCollection = db.collection('/surveys')
return (
surveyCollection
.get()
// eslint-disable-next-line promise/always-return
.then(querySnapshot => {
let surveyList = []
querySnapshot.forEach(doc => {
const survey = doc.data()
surveyList.push(survey)
})
response.send(surveyList)
})
)
})
app.get('/surveys/:survey', (request, response) => {
const surveyId = request.params.survey
const userAnswers = db.collection(`/surveys/${surveyId}/submissions`)
return (
userAnswers
.get()
// eslint-disable-next-line promise/always-return
.then(querySnapshot => {
let surveySubmissions = []
querySnapshot.forEach(doc => {
const userSubmission = doc.data()
surveySubmissions.push({
..._.mapValues(userSubmission.answers, getObjectValues), // format answers
...userSubmission.anonUser,
})
})
response.setHeader('Content-disposition', 'attachment; filename=cna.json')
response.set('Content-Type', 'application/json')
response.status(200).send(surveySubmissions)
})
.catch(error => {
console.log(error)
})
)
})
Хостинг + ветвь функций, я набираю 'firebase deploy'
terminal output:
i deploying functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint \surveyplus-cna\functions
> eslint .
+ functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (82.32 KB) for uploading
+ functions: functions folder uploaded successfully
i hosting[surveyplus-effd5]: beginning deploy...
i hosting[surveyplus-effd5]: found 30 files in build
+ hosting[surveyplus-effd5]: file upload complete
i functions: updating Node.js 8 function webApi(us-central1)...
+ functions[webApi(us-central1)]: Successful update operation.
i hosting[surveyplus-effd5]: finalizing version...
+ hosting[surveyplus-effd5]: version finalized
i hosting[surveyplus-effd5]: releasing new version...
+ hosting[surveyplus-effd5]: release complete
+ Deploy complete!
В облачной функции только ветвь firebase deploy
выход
=== Deploying to '...'...
i deploying functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint \surveyplus-cna\functions
> eslint .
+ functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (82.33 KB) for uploading
+ functions: functions folder uploaded successfully
i hosting[surveyplus-effd5]: beginning deploy...
i hosting[surveyplus-effd5]: found 30 files in build
+ hosting[surveyplus-effd5]: file upload complete
i functions: updating Node.js 8 function webApi(us-central1)...
+ functions[webApi(us-central1)]: Successful update operation.
i hosting[surveyplus-effd5]: finalizing version...
+ hosting[surveyplus-effd5]: version finalized
i hosting[surveyplus-effd5]: releasing new version...
+ hosting[surveyplus-effd5]: release complete
+ Deploy complete!