Is there a way to deploy Next.js SSR to Firebase Hosting like Angular Universal?

47 Views Asked by At

my goal is to use Next.js because it has Functions: cookies. Which I intend to use for CSRF Token.

However, I am not sure how to deploy Next.js to Firebase Hosting. In Angular, I can deploy SSR website using a Cloud Function accountUniversal.

Run this command to build the Angular project

npm run build:ssr:account
npm run build:functions
npx firebase deploy --only hosting:account,functions:accountUniversal

firebase.json

  "hosting": [
    {
      "target": "account",
      "public": "dist/account/browser",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "rewrites": [
        {
          "source": "**",
          "function": "accountUniversal"
        }
      ]
    },

package.json

"build:ssr:account": "ng build --project account && ng run account:server && npm run --prefix functions copy:account",
"build:functions": "npm run --prefix functions build",

functions/package.json

"copy:account": "rm -rf ./dist/account && mkdir -p ./dist/account && cp -r ../dist/account ./dist/",
"build": "tsc",

functions/src/features/account/universal/account-universal.ts

import {onRequest} from "firebase-functions/v2/https";
import {info} from "firebase-functions/logger";

export const accountUniversal = onRequest((request, response) => {
  info("accountUniversal");

  // eslint-disable-next-line @typescript-eslint/no-var-requires
  require("../../../../dist/account/server/main")
    .app()(request, response);
});

0

There are 0 best solutions below