【问题标题】:NextJS with Firebase Cloud FunctionsNextJS 与 Firebase 云功能
【发布时间】:2017-12-24 10:10:13
【问题描述】:

我想将 NextJS 与 firebase 云功能一起使用,我正在创建一个云功能:

import * as functions from 'firebase-functions';
import cors from 'cors';
import express from 'express';
import next from 'next';

const nextApp = next({ dev: false });
const handle = nextApp.getRequestHandler();

nextApp
  .prepare()
  .then(() => {
    const server = express();
    server.use(cors({ origin: true }));

    server.get('/a', (req, res) => {
      return nextApp.render(req, res, '/b', req.query);
    });

    server.get('/b', (req, res) => {
      return nextApp.render(req, res, '/a', req.query);
    });

    server.get('*', (req, res) => {
      return handle(req, res);
    });
  })
  .catch(ex => {
    console.error(ex.stack);
    process.exit(1);
  });

export let app = functions.https.onRequest(nextApp);

NextJS 使用我的 JS 应用程序的构建创建一个文件夹。

问题是我无法将 NextJS 构建文件夹上传到云端。 如何包含此文件夹?

GitHub 问题 => https://github.com/zeit/next.js/issues/2017

【问题讨论】:

    标签: javascript firebase google-cloud-functions nextjs


    【解决方案1】:

    我必须将firebase deploy 运行到functions 目录而不是root。 这是我的回购 => https://github.com/sarovin/next-firebase-functions

    【讨论】:

      【解决方案2】:

      Firebase 目前忽略在 Cloud Functions 中上传隐藏文件。 PR 已被合并以解决此问题,但我相信此时仍未发布。

      完成此排序后,您会发现在 Cloud Functions 上托管 Next.js 时会遇到许多其他问题。例如,JS 包存储在 /_next/ 路由中,除非您使用正确的 Firebase 托管重写规则,否则无法访问。

      我写了a blog post,涵盖了我在让 Next.js 在 Cloud Functions 上工作时发现的所有问题和注意事项。

      【讨论】:

        猜你喜欢
        • 2020-06-09
        • 2020-02-24
        • 2018-11-29
        • 2018-05-09
        • 2019-08-05
        • 2021-04-24
        • 2018-06-02
        • 2020-06-13
        相关资源
        最近更新 更多