函数执行耗时60060 ms,状态为“超时”谷歌云功能

问题描述

我正在尝试将我的nodejs工作上传到googlecloud函数上,但是我在日志中收到超时错误。我正在尝试使用模板加载主页。我无法正确使用helloworld函数。下面是代码的一部分,而不是完整的代码

exports.helloworld = ()=>{
    app.get('/',(req,res)=> {
        res.render('home');
    });
}

app.listen(3000,() => {
    console.log('app Now listening for requests on port 3000');
});

解决方法

如果要在云函数中使用express js路由,则需要导出express js应用程序而不是运行服务器。

index.js

const express = require('express');
const app = express();
app.get('/',(req,res)=> {
    res.render('home');
});
app.get('/login',res)=> {
    res.render('login');
});
exports.helloworld = app;