简体   繁体   English

使用 Firebase CLI 打印托管默认值 URL(或频道 URL)

[英]Print hosting default URL (or channel URL) with Firebase CLI

The Firebase CLI tool can show me the default URLs of the hosting site(s) of a project in a human-readable format: Firebase CLI 工具可以以人类可读的格式向我显示项目托管站点的默认 URL:

$ firebase hosting:sites:list

Sites for project <my-app>

┌──────────────────┬──────────────────────────────────┬─────────────────┐
│ Site ID          │ Default URL                      │ App ID (if set) │
├──────────────────┼──────────────────────────────────┼─────────────────┤
│ my-app           │ https://<my-app>.web.app         │ --              │
└──────────────────┴──────────────────────────────────┴─────────────────┘

If I have multiple channels, it can also show me the URLs for each channel on a given site:如果我有多个频道,它还可以显示给定站点上每个频道的 URL:

$ firebase hosting:channel:list

Channels for site <my-app>

┌────────────┬─────────────────────┬──────────────────────────────────┬─────────────┐
│ Channel ID │ Last Release Time   │ URL                              │ Expire Time │
├────────────┼─────────────────────┼──────────────────────────────────┼─────────────┤
│ live       │ 2022-10-27 15:06:54 │ https://<my-app>.web.app         │ never       │
└────────────┴─────────────────────┴──────────────────────────────────┴─────────────┘

But how do I print only the URL of a channel, for use in a shell script?但是我如何打印一个频道的 URL,用于 shell 脚本? (Without resorting to regexes.) (不求助于正则表达式。)

There isn't any command that prints just the default URLs.没有任何命令只打印默认 URL。 The CLI uses a package cli-table and prints all the data together. CLI 使用 package 客户cli-table并将所有数据打印在一起。

You can however use the Firebase Hosting REST API to list all the sites of a project and their channels and create a script or even better fork the Firebase CLI and add a new function alongside listSites() function of the CLI to print the URLs without the table.但是,您可以使用Firebase Hosting REST API列出项目的所有站点及其频道并创建脚本,或者甚至更好地分叉Firebase CLI并添加一个新的 function 旁边的listSites() 88340084806589桌子。

The REST APIs response is just an array of sites so it should be pretty straightforward: REST API 响应只是一组站点,因此应该非常简单:

{
  "sites": [
    {
      "name": "projects/<project_id>/sites/<site_id>",
      "defaultUrl": "https://<project_id>.web.app",
      "type": "DEFAULT_SITE"
    }
  ]
}

You can use --json argument.您可以使用--json参数。

Combine with jq, you can retrieve specific url.结合jq,可以检索出具体的url。

Example with live channel:直播频道示例:

$ firebase hosting:channel:list --json |\
jq '.result.channels[]|select(.name|contains("live")) | .url'

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

相关问题 Firebase 托管图像 URL 最佳实践 - Firebase Hosting Image URL best practice Firebase 托管复制和粘贴动态 url 不工作 - Firebase Hosting copy and paste dynamic url not working 如何配置 firebase.json 中的托管行为以重写 URL? - How to Configure hosting behavior in firebase.json to rewrite URL? 如何从托管URL的firebase与API服务器通信? - How can I communicate with the API server from the firebase hosting URL? url_launche 在本地与 firebase 托管中的行为不同 - url_launche behaves differently in local vs firebase hosting 如何使用 Firebase 为 Flutter Web 加载特定的 url 页面 - How can I load a specific url page using Firebase Hosting for Flutter Web 是否可以将云 Function 调用结果缓存在 Firebase 中独立于请求的 URL 托管重写? - Is it possible to cache Cloud Function invocation result in Firebase Hosting rewrite indepedently of the requested URL? 访问我的 Firebase 托管 web 应用程序(无自定义 URL)后,如何解决“ERR CERT COMMON NAME INVALID”页面? - How do I resolve "ERR CERT COMMON NAME INVALID" page after visiting my Firebase hosting web app (no custom URL)? How to print pdf file which comes from firebase url in API response in flutter? - How to print pdf file which comes from firebase url in API response in flutter? 如何知道Firebase Hosting中默认域的IP地址 - How to know the IP address of the default domain in Firebase Hosting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM