【发布时间】:2019-03-19 00:32:26
【问题描述】:
我正在尝试在 Firebase 上托管 Nuxt.js 应用程序,并且我已关注此 tutorial,但在尝试执行 sudo firebase serve --only functions, hosting 时遇到了 #10。我一直收到这个Timed out waiting for function to respond.。
经过进一步调查,我发现问题出在 /functions/index.js 中。 nuxt.renderRoute('/').then(...) 行将永远运行,因为从未调用过 console.log('After render')。这是 /functions/index.js 的样子
/functions/index.js
const functions = require('firebase-functions')
const express = require('express')
const { Nuxt } = require('nuxt')
const app = express()
const config = {
dev: false,
buildDir: 'nuxt',
build: {
publicPath: '/public/'
}
}
const nuxt = new Nuxt(config)
app.get('**', function (req, res) {
res.set('Cache-Control', 'public, max-age=600, s-maxage=1200')
console.log('it still works here')
nuxt.renderRoute('/').then(result => {
console.log(result.html)
res.send(result.html)
}).catch(e => {
console.log(e)
res.send(e)
})
console.log('After render')
})
module.exports.nuxtApp = functions.https.onRequest(app)
【问题讨论】:
-
我正在检查图像。日志说:
It still works here,但在您发布的代码中,没有出现。你能粘贴整个代码吗?我认为您在index.js中的方法签名是错误的。 -
@MrMins 哎呀我的错误。它应该打印
it still works here。我已经更新了这个问题。谢谢
标签: javascript firebase google-cloud-functions nuxt.js