使用 Firebase Hosting 托管 app-ads.txt

准备工作

  • 首先,你需要注册Firebase账号。
  • 然后,创建Firebase项目。
  • 生成app-ads.txt文件。

安装 Firebase CLI

1.安装

1
curl -sL https://firebase.tools | bash

2.登录并测试 Firebase CLI

1
firebase login

注意:firebase login 命令会打开与机器上的 localhost 关联的网页。如果您使用的是远程机器且您无权访问 localhost,请运行带有 –no-localhost 标志的命令。

初始化 Firebase 项目

切换到项目目录,然后执行以下命令:

1
firebase init

注意:firebase init 命令不会创建新目录。如果您要设置一个新应用,必须先创建一个目录,然后在该目录下运行 firebase init。

根据提示,选择:

1
2
Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub 
Action deploys

然后,可以选择创建已有的项目,或者新建。前面准备工作中我们已经创建项目,所以选择已有项目即可。

配置app-ads.txt

app-ads.txt文件放置到public目录下面即可。

部署

1
firebase deploy --only hosting

验证

在浏览器输入一下链接并打开。

1
https://PROJECT_ID.web.app/app-ads.txt

其中,PROJECT_ID是你的项目名

如果能够正确访问app-ads.txt中的内容,说明配置成功。

One More Thing

如果你有自己的网站,可以将主页重定向到你的网站,在firebase.json 文件中添加redirects 键值。

1
2
3
4
5
6
7
8
9
10
"hosting": {
...
"redirects": [
{
"source": "/",
"destination": "https://www.example.com",
"type": 301
}
]
}

如果没有的话,也可以自己写一个静态网页替换public目录下的index.html文件。

然后,执行部署命令完成部署即可。