【问题标题】:Function execution took 60060 ms, finished with status: 'timeout'. Google cloud functions函数执行耗时 60060 毫秒,完成状态为:“超时”。谷歌云功能
【发布时间】:2020-12-01 05:03:00
【问题描述】:

我正在尝试在 googlecloud 功能上上传我的 nodejs 工作,但我在日志中收到超时错误。我正在尝试使用模板加载主页。我无法正确使用 helloworld 功能。以下是部分代码,并非完整代码。

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

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

【问题讨论】:

  • Cloud Functions 不支持编写监听端口的代码。 Cloud Functions 管理套接字,您只需编写触发代码。我建议回到文档并按照其示例进行操作。

标签: javascript express google-app-engine google-cloud-functions


【解决方案1】:

如果你想在云端功能中使用 express js 路由,你需要导出 express js 应用,而不是运行服务器。

index.js

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

【讨论】:

    猜你喜欢
    • 2020-09-13
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 2017-08-26
    • 2020-05-11
    • 1970-01-01
    相关资源
    最近更新 更多