【问题标题】:Deployed NextJS over Firebase but getting Error 403 Forbidden在 Firebase 上部署 NextJS 但出现错误 403 Forbidden
【发布时间】:2021-06-16 09:30:05
【问题描述】:

我刚刚通过 Firebase Hosting 和 Firebase Functions 部署了我的 NextJS 应用。部署成功后,我去了网站,但我看到了这个页面。

这是我的firebase.json

{
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "function": "nextApp"
      }
    ]
  },
  "functions": {
    "source": ".",
    "predeploy": [
      "npm install",
      "npm run build"
    ],
    "runtime": "nodejs12",
    "ignore": [
      "**/tests/**",
      "**/node_modules/**",
      "jest.config.js"
    ]
  }
}

我的 nextJS 的云函数

// This file is an entry point for Firebase Function to serve NextJS
const functions = require('firebase-functions');
const { default: next } = require('next');

const dev = process.env.NODE_ENV !== 'production';
const app = next({
  dev,
  conf: {
    distDir: '.next',
    future: {
      strictPostcssConfiguration: false,
      excludeDefaultMomentLocales: true,
      webpack5: false,
    },
  },
});
const handle = app.getRequestHandler();

exports.nextApp = functions.region('asia-southeast2').https.onRequest((req, res) => {
  console.log('File: ' + req.originalUrl);
  return app.prepare().then(() => handle(req, res));
});

我确实检查了 Google Cloud Console,并确保我已将 allUsers 添加到 Cloud Function Invoker 角色,但它没有帮助。

【问题讨论】:

  • 请不要发布您的代码截图或其他文本内容。而是发布实际文本,并使用 Stack Overflow 的格式化工具进行标记。

标签: reactjs firebase http google-cloud-functions next.js


【解决方案1】:

对不起,愚蠢的我,我想通了。问题是因为我将 Cloud Functions 部署到 asia-southeast2 区域,但 Firebase Hosting 只能访问托管在 us-central1 中的 Cloud Functions。

【讨论】:

    猜你喜欢
    • 2021-10-05
    • 2020-12-22
    • 1970-01-01
    • 2014-12-19
    • 2023-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-28
    相关资源
    最近更新 更多