繁体   English   中英

Firebase 托管“重写”以访问 Google Cloud Run 上的 Next.js 应用程序

[英]Firebase Hosting "rewrites" to Access Next.js App on Google Cloud Run

我们正在使用 Firebase 托管。 我们有一个名为“知识”的 Next.js 应用程序,部署在同一个 GCP 项目中的 Google Cloud Run 上。 我们按照Firebase 文档中的说明进行操作。 我们的firebase.json如下:

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "hosting": {
    "public": "build",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "/knowledge{,/**}",
        "run": {
          "serviceId": "knowledge",
          "region": "us-central1"
        }
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

我们希望通过 Cloud Run 上的 Next.js 应用对“/knowledge{,/**}”的每个请求进行服务器端渲染。 当我们打开这些页面中的任何一个时,它会加载,但不会加载任何 static 文件,在控制台中显示许多错误,如下所示:

Uncaught SyntaxError: Unexpected token '<' (at webpack-df4cf1c8d23aa877.js:1:1)
framework-81da43a8dcd978d9.js:1

我们的next.config.js如下:

module.exports = {
  async rewrite() {
    return [
      {
        source: "/knowledge",
        destination: "/",
      },
    ];
  },
  images: {
    domains: ["firebasestorage.googleapis.com"],
  },
};

Static 文件将在 /_next/ 下,因此添加“/path*”。

module.exports = {
  async rewrite() {
    return [
      {
        source: "/knowledge",
        destination: "/",
      },
      {
        source: "/knowledge/:path*",
        destination: "/:path*",
      },
    ];
  },
  images: {
    domains: ["firebasestorage.googleapis.com"],
  },
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM