<?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: orange cherry</title>
    <description>The latest articles on DEV Community by orange cherry (@orange_cherry_).</description>
    <link>https://dev.to/orange_cherry_</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%2F2274796%2Fc509ca18-2df2-42ac-a1f1-e31f79019d14.jpg</url>
      <title>DEV Community: orange cherry</title>
      <link>https://dev.to/orange_cherry_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/orange_cherry_"/>
    <language>en</language>
    <item>
      <title>Weekly GitHub Project: NewsNow - Elegantly Reading Real-Time Trending News</title>
      <dc:creator>orange cherry</dc:creator>
      <pubDate>Fri, 25 Oct 2024 17:58:08 +0000</pubDate>
      <link>https://dev.to/orange_cherry_/weekly-github-project-newsnow-elegantly-reading-real-time-trending-news-46en</link>
      <guid>https://dev.to/orange_cherry_/weekly-github-project-newsnow-elegantly-reading-real-time-trending-news-46en</guid>
      <description>&lt;h1&gt;
  
  
  *&lt;em&gt;Weekly GitHub Project: NewsNow - Elegantly Reading Real-Time Trending *&lt;/em&gt;
&lt;/h1&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Project Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This week, we're introducing &lt;strong&gt;NewsNow&lt;/strong&gt;, a news aggregation platform that allows you to &lt;strong&gt;elegantly read real-time trending news&lt;/strong&gt;. NewsNow quickly aggregates real-time news from multiple data sources, offering a smooth reading experience that helps users easily access the latest trending information. This project supports GitHub OAuth login and uses Cloudflare D1 database to manage and store data.&lt;/p&gt;

&lt;p&gt;In this guide, I'll walk you through the step-by-step process of deploying this open-source project on &lt;strong&gt;Cloudflare Pages&lt;/strong&gt;. You’ll learn how to set up GitHub OAuth login, configure Cloudflare D1 database, and successfully deploy the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Deployment Guide&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Preparation&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1.1 Required Accounts&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Account&lt;/strong&gt;: To fork and manage the project code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloudflare Account&lt;/strong&gt;: To deploy and host the project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1.2 GitHub OAuth Application Setup&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;To enable GitHub login, you need to create an OAuth application on GitHub.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to GitHub and go to &lt;a href="https://github.com/settings/developers" rel="noopener noreferrer"&gt;Developer Settings&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;OAuth Apps&lt;/strong&gt; and click &lt;strong&gt;New OAuth App&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Fill in the application details:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Application name&lt;/strong&gt;: &lt;code&gt;NewsNow&lt;/code&gt; (or any name you prefer).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Homepage URL&lt;/strong&gt;: Use the URL of your forked GitHub repository for now, e.g., &lt;code&gt;https://github.com/your-username/newsnow&lt;/code&gt;. You can change this later to the deployed URL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authorization callback URL&lt;/strong&gt;: Use the format &lt;code&gt;https://your-cloudflare-pages-url/api/auth/callback&lt;/code&gt;, replacing &lt;code&gt;your-cloudflare-pages-url&lt;/code&gt; with your Cloudflare Pages URL after deployment.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;After registration, save the &lt;strong&gt;Client ID&lt;/strong&gt; and &lt;strong&gt;Client Secret&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2rit2n8ivsq34na28ttq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2rit2n8ivsq34na28ttq.png" alt="Image description" width="668" height="616"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Fork the GitHub Project&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Go to the original project page on GitHub: &lt;a href="https://github.com/ourongxing/newsnow" rel="noopener noreferrer"&gt;NewsNow Project&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;Fork&lt;/strong&gt; button at the top right to fork the project to your GitHub account.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vxjn6yh956rmb74xtz0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vxjn6yh956rmb74xtz0.png" alt="Image description" width="800" height="575"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3. Cloudflare Pages Deployment&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3.1 Connect GitHub&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Log in to your Cloudflare account.&lt;/li&gt;
&lt;li&gt;In the Cloudflare dashboard, go to &lt;strong&gt;"Workers &amp;amp; Pages"&lt;/strong&gt; on the left menu.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;"Create a Project"&lt;/strong&gt; and choose &lt;strong&gt;“Connect to Git”&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Authorize Cloudflare to access your GitHub account and select the &lt;code&gt;newsnow&lt;/code&gt; repository that you forked.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3.2 Configure Cloudflare Pages Project&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Choose the &lt;code&gt;newsnow&lt;/code&gt; repository and proceed to the build settings page.&lt;/li&gt;
&lt;li&gt;Set up the build parameters:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Framework preset&lt;/strong&gt;: Choose &lt;code&gt;None&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build command&lt;/strong&gt;: Enter &lt;code&gt;pnpm install &amp;amp;&amp;amp; pnpm build&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build output directory&lt;/strong&gt;: Enter &lt;code&gt;dist&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3.3 Configure Environment Variables&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;On the build settings page, click &lt;strong&gt;"Environment variables (advanced)"&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Add the following environment variables:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;G_CLIENT_ID&lt;/code&gt;: Your GitHub OAuth application's Client ID.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;G_CLIENT_SECRET&lt;/code&gt;: Your GitHub OAuth application's Client Secret.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;JWT_SECRET&lt;/code&gt;: It's recommended to use the same value as &lt;code&gt;G_CLIENT_SECRET&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;INIT_TABLE&lt;/code&gt;: Set to &lt;code&gt;true&lt;/code&gt; for the first deployment to initialize the database.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4. Create Cloudflare D1 Database&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;4.1 Create the Database&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;In the Cloudflare dashboard, navigate to &lt;strong&gt;"Workers &amp;amp; Pages"&lt;/strong&gt; -&amp;gt; &lt;strong&gt;"D1 SQL Database"&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;“Create Database”&lt;/strong&gt;, and enter a name, e.g., &lt;code&gt;newsnow_db&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Note down the &lt;strong&gt;Database ID&lt;/strong&gt; and &lt;strong&gt;Database Name&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;4.2 Configure the &lt;code&gt;wrangler.toml&lt;/code&gt; File&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;In your GitHub repository, create or edit the &lt;code&gt;wrangler.toml&lt;/code&gt; file in the project's root directory.&lt;/li&gt;
&lt;li&gt;Add the following configuration to the &lt;code&gt;wrangler.toml&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;   &lt;span class="py"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"newsnow-project"&lt;/span&gt;  &lt;span class="c"&gt;# Your project name&lt;/span&gt;
   &lt;span class="py"&gt;type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"javascript"&lt;/span&gt;

   &lt;span class="nn"&gt;[[d1_databases]]&lt;/span&gt;
   &lt;span class="py"&gt;binding&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"NEWSNOW_DB"&lt;/span&gt;
   &lt;span class="py"&gt;database_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"your_database_name"&lt;/span&gt;  &lt;span class="c"&gt;# Replace with your created database name&lt;/span&gt;
   &lt;span class="py"&gt;database_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"your_database_id"&lt;/span&gt;      &lt;span class="c"&gt;# Replace with your created database ID&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Commit the changes to GitHub.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;4.3 Redeploy the Project&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Go back to the Cloudflare Pages project page.&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;“Deploy”&lt;/strong&gt; button to redeploy the project.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;5. Deployment Verification&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;5.1 Access the Project&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Wait for the deployment to complete.&lt;/li&gt;
&lt;li&gt;Visit the URL provided by Cloudflare Pages to ensure the page loads correctly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndva7ruqewoawwfz26wd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndva7ruqewoawwfz26wd.png" alt="Image description" width="800" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;5.2 Adjust Database Initialization Setting&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;If the project is deployed successfully and data is loading correctly, go back to the Cloudflare Pages project settings.&lt;/li&gt;
&lt;li&gt;Change the &lt;code&gt;INIT_TABLE&lt;/code&gt; environment variable from &lt;code&gt;true&lt;/code&gt; to &lt;code&gt;false&lt;/code&gt; to prevent the database from re-initializing on future deployments.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;5.3 Test GitHub OAuth Login&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Try logging in with your GitHub account.&lt;/li&gt;
&lt;li&gt;If the login fails, check if the &lt;strong&gt;Authorization callback URL&lt;/strong&gt; in the GitHub OAuth settings matches the Cloudflare Pages URL.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;6. Optional Configuration and Extensions&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;6.1 Custom Domain&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If you have your own domain, you can set up a custom domain in Cloudflare Pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;6.2 Extend Data Sources&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Modify or add new data sources by editing the directories &lt;code&gt;shared/metadata&lt;/code&gt;, &lt;code&gt;shared/sources&lt;/code&gt;, and &lt;code&gt;server/sources&lt;/code&gt; according to your needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;6.3 Debugging and Logs&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Use the debugging and log tools provided by Cloudflare to monitor the project’s performance.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
