首页 > 解决方案 > 在 Firebase 中托管多个具有动态内容的站点

问题描述

Firebase 托管多个具有动态内容的网站。下面的文件我正在使用基于目标的托管到其中一个站点。但有些是如何失败的。

将目标应用于站点的命令

目标:申请托管目标名称目标站点

部署命令

firebase deploy --only 托管:目标名称

firebase.json

{
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ],
    "source": "functions"
  },
  "hosting": {
    "public": "public",
    "target": "target-name",
    "rewrites": [
       {
        "source": "/**",
        "function": "function"
      }
    ]
  }
}

错误日志:

> [2019-08-02T08:02:33.699Z]
> ---------------------------------------------------------------------- [2019-08-02T08:02:33.703Z] Command:      
> /home/johndoe/.nvm/v10.9.0/bin/node
> /home/johndoe/.nvm/v10.9.0/bin/firebase deploy --only
> hosting:target-name --debug [2019-08-02T08:02:33.703Z] CLI Version:  
> 6.4.0 [2019-08-02T08:02:33.703Z] Platform:      linux [2019-08-02T08:02:33.703Z] Node Version:  v10.9.0
> [2019-08-02T08:02:33.704Z] Time:          Fri Aug 02 2019 13:32:33
> GMT+0530 (India Standard Time) [2019-08-02T08:02:33.704Z]
> ----------------------------------------------------------------------
> 
> [2019-08-02T08:02:33.712Z] > command requires scopes:
> ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
> [2019-08-02T08:02:33.713Z] > authorizing via signed-in user
> [2019-08-02T08:02:33.713Z] [iam] checking project first for
> permissions ["firebase.projects.get","firebasehosting.sites.update"]
> [2019-08-02T08:02:33.718Z] >>> HTTP REQUEST POST
> https://cloudresourcemanager.googleapis.com/v1/projects/first:testIamPermissions
> permissions=[firebase.projects.get, firebasehosting.sites.update]
> [2019-08-02T08:02:35.337Z] <<< HTTP RESPONSE 200
> content-type=application/json; charset=UTF-8, vary=X-Origin, Referer,
> Origin,Accept-Encoding, date=Fri, 02 Aug 2019 08:05:56 GMT,
> server=ESF, cache-control=private, x-xss-protection=0,
> x-frame-options=SAMEORIGIN, x-content-type-options=nosniff,
> server-timing=gfet4t7; dur=1407, alt-svc=quic=":443"; ma=2592000;
> v="46,43,39", accept-ranges=none, transfer-encoding=chunked
> [2019-08-02T08:02:35.340Z] >>> HTTP REQUEST GET
> https://firebase.googleapis.com/v1beta1/projects/first   
> [2019-08-02T08:02:35.816Z] <<< HTTP RESPONSE 200
> content-type=application/json; charset=UTF-8, vary=X-Origin, Referer,
> Origin,Accept-Encoding, date=Fri, 02 Aug 2019 08:05:57 GMT,
> server=ESF, cache-control=private, x-xss-protection=0,
> x-frame-options=SAMEORIGIN, x-content-type-options=nosniff,
> alt-svc=quic=":443"; ma=2592000; v="46,43,39", accept-ranges=none,
> transfer-encoding=chunked [2019-08-02T08:02:38.550Z] TypeError: Cannot
> read property 'deploys' of undefined
>     at /home/prateekk/.nvm/v10.9.0/lib/node_modules/firebase-tools/lib/deploy/index.js:88:36
>     at process._tickCallback (internal/process/next_tick.js:68:7)

教程

标签: firebasefirebase-hosting

解决方案


经过大量的挖掘。最后它对我有用。下面是我的 firebase.json 结构。

使用数组结构进行托管并运行“ firebase init hosting ”-重置 firebase.json

firebase.json

{
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ],
    "source": "functions"
  },
  "hosting": [{
    "public": "public",
    "target": "target-name",
    "ignore": [
    "firebase.json",
    "**/.*",
    "**/node_modules/**"
    ],
    "rewrites": [
       {
        "source": "/**",
        "function": "function"
      }
    ]
  }]
}

推荐阅读