【问题标题】:Firebase cloud functions work locally but not after deploymentFirebase 云功能在本地工作,但在部署后不工作
【发布时间】:2018-07-28 06:46:38
【问题描述】:

我目前正在尝试将 Nuxt SSR 应用部署到 Firebase。

在本地和 firebase 服务器上一切正常。云函数正确执行并渲染html,没问题。

当我向外部 API (Storyblok) 添加请求时会出现问题。我在 Blaze 计划中,所以外部请求应该可以工作,对吧?

使用云功能模拟器并通过firebase serve --only functions,hosting 使用外部 API 请求,一切都在本地运行,但部署后出现错误 500。

有没有办法更详细地记录 Firbase 端可能发生的事情?

云功能:

const functions = require('firebase-functions');
const { Nuxt } = require('nuxt');
const express = require('express');
const app = express();

const config = {
  dev: false,
  buildDir: 'nuxt',
  build: {
    publicPath: '/assets/'
  }
}
const nuxt = new Nuxt(config);

function handleRequest(req, res) {
  res.set('Cache-Control', 'public, max-age=150, s-maxage=150');
  return new Promise((resolve, reject) => {
    nuxt.render(req, res, promise => {
      promise.then(resolve).catch(reject)
    })
  });
}

app.use(handleRequest);
exports.nuxtssr = functions.https.onRequest(app);

【问题讨论】:

    标签: javascript firebase google-cloud-functions


    【解决方案1】:

    尝试在 Nuxt 配置中添加 debug: true。

    即

    const config = {
      debug: true,
      dev: false,
      buildDir: 'nuxt',
      build: {
        publicPath: '/assets/'
      }
    }
    

    这将使错误消息显示在浏览器中,而不仅仅是错误 500。

    【讨论】:

      【解决方案2】:

      推荐你:

      https://firebase.google.com/docs/functions/writing-and-viewing-logs#viewing_logs

      也许这会有更多使用 Firebase CLI 的详细信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-17
        • 1970-01-01
        • 2020-01-07
        • 1970-01-01
        • 2020-04-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多