NodeJS 部署Firebase Web应用程序时出现404错误

sczxawaw  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(87)

嗨,当我部署我的firebase web应用程序时,我在访问端点时遇到404 not found错误。
下面是我的src/routes/functions文件夹中的index.js文件的一部分。

const port = process.env.PORT || 80;
server.listen(port,'127.0.0.1');
console.debug('Server listening on port ' + port);

// Your web app's Firebase configuration
var firebaseConfig = {
  apiKey: "*",
  authDomain: "*",
  databaseURL: "*",
  projectId: "*",
  storageBucket: "*",
  messagingSenderId: "93371481008",
  appId: "*",
  measurementId: "G-NR8N5HP6RZ"
};
// Initialize Firebase
if (!firebase.apps.length) {
  firebase.initializeApp(firebaseConfig);
}else {
  firebase.app(); // if already initialized, use that one
}
router.get('/test', function(req,res){
  console.log("router map test");
  res.send("test page");
});

字符串
当我通过键入sudo firebase deploy来部署Firebase Web应用程序时,
当我尝试访问index. js-curl -X GET https://PROJECT_ID/test中的测试端点时,我得到了一个404错误。
下面是我的firebase.json文件:

"hosting": {
    "public": "src/main/www",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  },```
  "functions": [
    {
      "source": "src/routes/functions",
      "codebase": "map-print",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ]
    }
  ],
  "rewrites": [
    {
      "source": "/test",
      "function": "test"
    }
  ]
}

fzsnzjdm

fzsnzjdm1#

您缺少导出函数本身。
我假设你使用express来处理你的路由,所以这里有一个最小的例子:

import express from 'express'

const app = express()
app.get('/test', req, res => {
  return res.send('hello world')
})

// this is what you're missing
exports.myFuncionName = functions.https.onRequest( app )

字符串

相关问题