Firebase HTTPS云功能在生产中返回404

时间:2018-12-13 18:44:34

标签: function firebase cloud google-cloud-functions

我已将一个非常基本的HTTP Cloud Function推送到Firebase,并且在尝试通过浏览器或通过邮递员进行访问时得到404。该功能可以通过firebase serve以及通过我使用firebase-functions-test SDK编写的各种测试在本地工作。

// import function libraries and initialize admin app
var functions = require('firebase-functions');
var admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)

// push data to a specific database
var pushData = (path) => (payload) => {
  return new Promise((resolve, reject) => {
    admin.database().ref(path).push(payload).then(snapshot => {
      resolve(snapshot)
    }).catch((error) => {
      reject(error)
    })
  })
}

// github webhook endpoint
exports.postGitHubEvent = functions.https.onRequest((request, response) => {
  // handle invalid request method
  if (request.method !== 'POST') {
    return response.send(405, 'Only POST Requests Are Accepted')
  }
  // push request body to database
  var event = request.body
  var writeData = pushData('github')(event)

  // return write promise
  return writeData.then(
    result => response.send(200, `Successfully Pushed Github Event: ${result}`),
    error => response.send(500, `Error in Pushing GitHub Event: ${error}`)
  )
})

1 个答案:

答案 0 :(得分:0)

已回答。我的Firebase项目ID中包含两个变量,并在创建项目时对其进行了自定义(编辑)。在项目名称/项目ID中保留一个hiphen,现在它可以正常运行...