Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用Firebase云功能中的express和Commit进行路由_Node.js_Express_Firebase_Google Cloud Functions - Fatal编程技术网

Node.js 使用Firebase云功能中的express和Commit进行路由

Node.js 使用Firebase云功能中的express和Commit进行路由,node.js,express,firebase,google-cloud-functions,Node.js,Express,Firebase,Google Cloud Functions,我想在我的Express应用程序中实现路由,该应用程序将通过云功能公开 这是我的函数/index.js文件: const functions = require('firebase-functions'); const express = require('express'); const consign = require('consign'); const app = express(); consign() .include("./routes") .into(ap

我想在我的Express应用程序中实现路由,该应用程序将通过云功能公开

这是我的函数/index.js文件:

const functions = require('firebase-functions');
const express = require('express');
const consign = require('consign');

const app = express();

  consign()
    .include("./routes")
    .into(app);

exports.api = functions.https.onRequest(app);
这是我的./routes/index.js文件

module.exports = app => {
    app.get('/', (req,res)=>{
    res.json({status:"success"});
})
}
所以我想这段代码足以承载一个云函数,当我调用这个托管url(由于隐私原因更改了url)时,它应该返回响应{“status”:“success”:}

相反,当我调用上面的url时,它会显示错误“错误:无法处理请求”


请帮助我如何在云功能中使用express and Commit模块

这有点晚了,但我想还是相关的。这就是我所做的:

consign({
  cwd: 'src'
})
.include("routes")
.into(app)
CWD设置基本目录,如文档中所述:

委托将只使用当前工作目录中的相对路径,但是,有时您不希望对象链中包含大量嵌套的文件,因此您可以设置cwd

在我的例子中,
src
是包含我的firebase函数代码(functions/src)的文件夹


希望有帮助

你有没有尝试过在没有委托的情况下托管一个express应用程序,先看看它是否管用?是的,它管用!!那么你是说,当你将委托添加到同一个应用程序时,出现了问题?