<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jumpei Ogawa</title>
    <description>The latest articles on DEV Community by Jumpei Ogawa (@phanect).</description>
    <link>https://dev.to/phanect</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F43209%2Fc4ca0505-2410-4b7d-a10f-acb8767d3e89.jpg</url>
      <title>DEV Community: Jumpei Ogawa</title>
      <link>https://dev.to/phanect</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/phanect"/>
    <language>en</language>
    <item>
      <title>How to create staging environment on Cloudflare Pages</title>
      <dc:creator>Jumpei Ogawa</dc:creator>
      <pubDate>Sun, 13 Feb 2022 14:29:30 +0000</pubDate>
      <link>https://dev.to/phanect/how-to-create-staging-environment-on-cloudflare-pages-7ha</link>
      <guid>https://dev.to/phanect/how-to-create-staging-environment-on-cloudflare-pages-7ha</guid>
      <description>&lt;p&gt;As far as I know, Cloudflare does not officially provide documents to set up staging environments on Cloudflare Pages.&lt;br&gt;
I raised a feature request to allow us creating staging environments, and then I got an advise how to create staging environments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Premises
&lt;/h2&gt;

&lt;p&gt;When you push or merge changes to the &lt;code&gt;staging&lt;/code&gt; branch on GitHub, the content of the &lt;code&gt;staging&lt;/code&gt; branch will be deployed and the deployment can be accessible from stg.example.com.&lt;br&gt;
The deployment of the &lt;code&gt;main&lt;/code&gt; branch can be accessible from example.com as well.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Project name of Cloudflare Pages: example-prj&lt;/li&gt;
&lt;li&gt;Name of the Git branch corresponding to the staging environment: &lt;code&gt;staging&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Domain name for staging environment: stg.example.com (You can also associate different apex domain like example-stg.com.)&lt;/li&gt;
&lt;li&gt;Name of the Git branch for production environment: &lt;code&gt;main&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Domain name for production environment: example.com&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Create &lt;code&gt;staging&lt;/code&gt; branch on GitHub
&lt;/h2&gt;

&lt;p&gt;Create it as usual.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Add stg.example.com to Custom Domains of Cloudflare Pages
&lt;/h2&gt;

&lt;p&gt;You can see Custom Domains tab on the Cloudflare Pages dashboard.&lt;br&gt;
Add stg.example.com from the tab.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Fix DNS so that stg.example.com points the deployment for &lt;code&gt;staging&lt;/code&gt; branch
&lt;/h2&gt;

&lt;p&gt;By adding the custom domain to Cloudflare Pages, the new CNAME record stg.example.com which points example-prj.pages.dev is automatically added to your DNS.&lt;/p&gt;

&lt;p&gt;Modify the DNS record value so that it points staging.example-prj.pages.dev.&lt;/p&gt;

&lt;p&gt;Note that you need to enable Cloudflare CDN (orange-cloud) for stg.example.com. If you disable Cloudflare CDN (gray-cloud), stg.example.com does not point staging deployment properly.&lt;/p&gt;

&lt;p&gt;(Therefore, I guess you cannot associate domain with staging deployment if you use a DNS provider other than Cloudflare. See next section for possible workaround.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this works?
&lt;/h2&gt;

&lt;p&gt;Actually, each deployments of the non-production branches are accessible with BRANCH_NAME.example-prj.pages.dev. We just associated the custom domain with it.&lt;/p&gt;

&lt;p&gt;As I mentioned, if you use a DNS other than Cloudflare, I guess you cannot associate custom domain with the staging deployment. You can use staging.example-prj.pages.dev as the staging environment.&lt;/p&gt;

</description>
      <category>cloudflare</category>
      <category>cloudflarepages</category>
    </item>
  </channel>
</rss>
