VercelのPreview環境に固定のサブドメインを割り当てる
Vercelを使うとブランチごとにPreview環境を用意してくれるのでとても便利。
カスタムドメイン設定を追加すると、ブランチに固定のサブドメインを設定することもできる。
↓はstagingブランチを staging.example.com
に固定する場合の設定例。

設定が完了すると固定のサブドメインでPreview環境にアクセスできるようになる。

また、ブランチ固有の環境変数を設定することもできる。

ただし、固定のサブドメインを設定したPreview環境の場合は、 X-Robots-Tag: noindex
の自動付与が行われないため、独自でnoindex対応を行う必要がある。
NOTE: If a Custom Domain is assigned to a non-Production Branch, it will not set the X-Robots-Tag: noindex header.
そこで、昨日の記事に書いたようにビルド時にrobots.txtを出し分けるようにした。
これで固定のサブドメインでアクセスできるPreview環境が作れた。