Home Web Front-end JS Tutorial Weekly GitHub Project: NewsNow - Elegantly Reading Real-Time Trending News

Weekly GitHub Project: NewsNow - Elegantly Reading Real-Time Trending News

Oct 27, 2024 am 06:13 AM

*Weekly GitHub Project: NewsNow - Elegantly Reading Real-Time Trending *

Project Introduction

This week, we're introducing NewsNow, a news aggregation platform that allows you to elegantly read real-time trending news. 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.

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

Deployment Guide

1. Preparation

1.1 Required Accounts

  • GitHub Account: To fork and manage the project code.
  • Cloudflare Account: To deploy and host the project.

1.2 GitHub OAuth Application Setup

To enable GitHub login, you need to create an OAuth application on GitHub.

  1. Log in to GitHub and go to Developer Settings.
  2. Choose OAuth Apps and click New OAuth App.
  3. Fill in the application details:
    • Application name: NewsNow (or any name you prefer).
    • Homepage URL: Use the URL of your forked GitHub repository for now, e.g., https://github.com/your-username/newsnow. You can change this later to the deployed URL.
    • Authorization callback URL: Use the format https://your-cloudflare-pages-url/api/auth/callback, replacing your-cloudflare-pages-url with your Cloudflare Pages URL after deployment.
  4. After registration, save the Client ID and Client Secret.

Weekly GitHub Project: NewsNow - Elegantly Reading Real-Time Trending News

2. Fork the GitHub Project

  1. Go to the original project page on GitHub: NewsNow Project.
  2. Click the Fork button at the top right to fork the project to your GitHub account.

Weekly GitHub Project: NewsNow - Elegantly Reading Real-Time Trending News

3. Cloudflare Pages Deployment

3.1 Connect GitHub

  1. Log in to your Cloudflare account.
  2. In the Cloudflare dashboard, go to "Workers & Pages" on the left menu.
  3. Click "Create a Project" and choose “Connect to Git”.
  4. Authorize Cloudflare to access your GitHub account and select the newsnow repository that you forked.

3.2 Configure Cloudflare Pages Project

  1. Choose the newsnow repository and proceed to the build settings page.
  2. Set up the build parameters:
    • Framework preset: Choose None.
    • Build command: Enter pnpm install && pnpm build.
    • Build output directory: Enter dist.

3.3 Configure Environment Variables

  1. On the build settings page, click "Environment variables (advanced)".
  2. Add the following environment variables:
    • G_CLIENT_ID: Your GitHub OAuth application's Client ID.
    • G_CLIENT_SECRET: Your GitHub OAuth application's Client Secret.
    • JWT_SECRET: It's recommended to use the same value as G_CLIENT_SECRET.
    • INIT_TABLE: Set to true for the first deployment to initialize the database.

4. Create Cloudflare D1 Database

4.1 Create the Database

  1. In the Cloudflare dashboard, navigate to "Workers & Pages" -> "D1 SQL Database".
  2. Click “Create Database”, and enter a name, e.g., newsnow_db.
  3. Note down the Database ID and Database Name.

4.2 Configure the wrangler.toml File

  1. In your GitHub repository, create or edit the wrangler.toml file in the project's root directory.
  2. Add the following configuration to the wrangler.toml file:
   name = "newsnow-project"  # Your project name
   type = "javascript"

   [[d1_databases]]
   binding = "NEWSNOW_DB"
   database_name = "your_database_name"  # Replace with your created database name
   database_id = "your_database_id"      # Replace with your created database ID
Copy after login
  1. Commit the changes to GitHub.

4.3 Redeploy the Project

  1. Go back to the Cloudflare Pages project page.
  2. Click the “Deploy” button to redeploy the project.

5. Deployment Verification

5.1 Access the Project

  1. Wait for the deployment to complete.
  2. Visit the URL provided by Cloudflare Pages to ensure the page loads correctly.

Weekly GitHub Project: NewsNow - Elegantly Reading Real-Time Trending News

5.2 Adjust Database Initialization Setting

  1. If the project is deployed successfully and data is loading correctly, go back to the Cloudflare Pages project settings.
  2. Change the INIT_TABLE environment variable from true to false to prevent the database from re-initializing on future deployments.

5.3 Test GitHub OAuth Login

  1. Try logging in with your GitHub account.
  2. If the login fails, check if the Authorization callback URL in the GitHub OAuth settings matches the Cloudflare Pages URL.

6. Optional Configuration and Extensions

6.1 Custom Domain

  • If you have your own domain, you can set up a custom domain in Cloudflare Pages.

6.2 Extend Data Sources

  • Modify or add new data sources by editing the directories shared/metadata, shared/sources, and server/sources according to your needs.

6.3 Debugging and Logs

  • Use the debugging and log tools provided by Cloudflare to monitor the project’s performance.

The above is the detailed content of Weekly GitHub Project: NewsNow - Elegantly Reading Real-Time Trending News. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1235
24
Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript Engines: Comparing Implementations JavaScript Engines: Comparing Implementations Apr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript: Exploring the Versatility of a Web Language JavaScript: Exploring the Versatility of a Web Language Apr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration) How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration) Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

From C/C   to JavaScript: How It All Works From C/C to JavaScript: How It All Works Apr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration) Building a Multi-Tenant SaaS Application with Next.js (Backend Integration) Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

See all articles