


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.
- Log in to GitHub and go to Developer Settings.
- Choose OAuth Apps and click New OAuth App.
- 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.
- After registration, save the Client ID and Client Secret.
2. Fork the GitHub Project
- Go to the original project page on GitHub: NewsNow Project.
- Click the Fork button at the top right to fork the project to your GitHub account.
3. Cloudflare Pages Deployment
3.1 Connect GitHub
- Log in to your Cloudflare account.
- In the Cloudflare dashboard, go to "Workers & Pages" on the left menu.
- Click "Create a Project" and choose “Connect to Git”.
- Authorize Cloudflare to access your GitHub account and select the newsnow repository that you forked.
3.2 Configure Cloudflare Pages Project
- Choose the newsnow repository and proceed to the build settings page.
- 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
- On the build settings page, click "Environment variables (advanced)".
- 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
- In the Cloudflare dashboard, navigate to "Workers & Pages" -> "D1 SQL Database".
- Click “Create Database”, and enter a name, e.g., newsnow_db.
- Note down the Database ID and Database Name.
4.2 Configure the wrangler.toml File
- In your GitHub repository, create or edit the wrangler.toml file in the project's root directory.
- 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
- Commit the changes to GitHub.
4.3 Redeploy the Project
- Go back to the Cloudflare Pages project page.
- Click the “Deploy” button to redeploy the project.
5. Deployment Verification
5.1 Access the Project
- Wait for the deployment to complete.
- Visit the URL provided by Cloudflare Pages to ensure the page loads correctly.
5.2 Adjust Database Initialization Setting
- If the project is deployed successfully and data is loading correctly, go back to the Cloudflare Pages project settings.
- 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
- Try logging in with your GitHub account.
- 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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Java and JavaScript are different programming languages, each suitable for different application scenarios. Java is used for large enterprise and mobile application development, while JavaScript is mainly used for web page development.

JavaScriptcommentsareessentialformaintaining,reading,andguidingcodeexecution.1)Single-linecommentsareusedforquickexplanations.2)Multi-linecommentsexplaincomplexlogicorprovidedetaileddocumentation.3)Inlinecommentsclarifyspecificpartsofcode.Bestpractic

PlacingtagsatthebottomofablogpostorwebpageservespracticalpurposesforSEO,userexperience,anddesign.1.IthelpswithSEObyallowingsearchenginestoaccesskeyword-relevanttagswithoutclutteringthemaincontent.2.Itimprovesuserexperiencebykeepingthefocusonthearticl

The following points should be noted when processing dates and time in JavaScript: 1. There are many ways to create Date objects. It is recommended to use ISO format strings to ensure compatibility; 2. Get and set time information can be obtained and set methods, and note that the month starts from 0; 3. Manually formatting dates requires strings, and third-party libraries can also be used; 4. It is recommended to use libraries that support time zones, such as Luxon. Mastering these key points can effectively avoid common mistakes.

JavaScriptispreferredforwebdevelopment,whileJavaisbetterforlarge-scalebackendsystemsandAndroidapps.1)JavaScriptexcelsincreatinginteractivewebexperienceswithitsdynamicnatureandDOMmanipulation.2)Javaoffersstrongtypingandobject-orientedfeatures,idealfor

Event capture and bubble are two stages of event propagation in DOM. Capture is from the top layer to the target element, and bubble is from the target element to the top layer. 1. Event capture is implemented by setting the useCapture parameter of addEventListener to true; 2. Event bubble is the default behavior, useCapture is set to false or omitted; 3. Event propagation can be used to prevent event propagation; 4. Event bubbling supports event delegation to improve dynamic content processing efficiency; 5. Capture can be used to intercept events in advance, such as logging or error processing. Understanding these two phases helps to accurately control the timing and how JavaScript responds to user operations.

JavaScripthassevenfundamentaldatatypes:number,string,boolean,undefined,null,object,andsymbol.1)Numbersuseadouble-precisionformat,usefulforwidevaluerangesbutbecautiouswithfloating-pointarithmetic.2)Stringsareimmutable,useefficientconcatenationmethodsf

If JavaScript applications load slowly and have poor performance, the problem is that the payload is too large. Solutions include: 1. Use code splitting (CodeSplitting), split the large bundle into multiple small files through React.lazy() or build tools, and load it as needed to reduce the first download; 2. Remove unused code (TreeShaking), use the ES6 module mechanism to clear "dead code" to ensure that the introduced libraries support this feature; 3. Compress and merge resource files, enable Gzip/Brotli and Terser to compress JS, reasonably merge files and optimize static resources; 4. Replace heavy-duty dependencies and choose lightweight libraries such as day.js and fetch
