feat: update news service to fetch Naver Stock news and enhance category handling

This commit is contained in:
2026-04-30 14:20:56 +08:00
parent 3d891d781c
commit aa9cf128d5
82 changed files with 414 additions and 87 deletions

View File

@@ -1,6 +1,6 @@
# News Service
独立新闻微服务,负责周期性从 NewsAPI 拉取新闻并落盘为 JSON 文件,再通过 HTTP 接口提供给前端。
独立新闻微服务,负责周期性从 Naver Stock 新闻接口拉取新闻并落盘为 JSON 文件,再通过 HTTP 接口提供给前端。
## 功能
@@ -12,20 +12,20 @@
## 分类
- finance
- business
- technology
- market
- flashnews
- mainnews
- ranknews
- worldnews
## 目录
```text
news_service/
data/
finance.json
business.json
technology.json
market.json
flashnews.json
mainnews.json
ranknews.json
worldnews.json
src/
app/
config/
@@ -76,15 +76,15 @@ GET /api/news/categories
### 获取指定分类新闻
```http
GET /api/news?category=finance&limit=10
GET /api/news/finance?limit=10
GET /api/news?category=flashnews&limit=10
GET /api/news/flashnews?limit=10
```
### 兼容前端现有 NewsAPI 调用
```http
GET /v2/everything?q=finance&language=ko&pageSize=10&page=1
GET /v2/top-headlines?category=business&country=ko&pageSize=10
GET /v2/everything?q=flashnews&language=ko&pageSize=10&page=1
GET /v2/top-headlines?category=mainnews&country=ko&pageSize=10
```
返回结构与前端当前使用的 NewsAPI 结构保持一致:
@@ -107,7 +107,7 @@ GET /api/news/all?limit=10
```http
POST /api/news/refresh
POST /api/news/refresh?category=finance
POST /api/news/refresh?category=flashnews
```
## Docker
@@ -123,8 +123,8 @@ cd /Users/wjp/Projects/juYou
docker compose -f docker-compose.news-stack.yml up -d --build
```
这样前端容器中的 Nginx 会把同源路径 `/newsapi/*` 代理到容器网络中的 `news-service:3100`,浏览器不会直接访问 NewsAPI,因此不会触发跨域限制。
这样前端容器中的 Nginx 会把同源路径 `/newsapi/*` 代理到容器网络中的 `news-service:3100`,浏览器不会直接访问外部新闻接口,因此不会触发跨域限制。
## 前端接入建议
前端如果继续使用原来的 `/newsapi/v2/*` 请求方式,只需要把代理目标指向本服务即可,不需要修改新闻请求代码。
前端如果继续使用原来的 `/newsapi/v2/*` 请求方式,只需要把代理目标指向本服务即可,不需要修改新闻请求代码。