diff --git a/newBackApi/app.js b/newBackApi/app.js index 911acf6..6efc7f1 100644 --- a/newBackApi/app.js +++ b/newBackApi/app.js @@ -10,6 +10,23 @@ import homeRouter from "./router/home.js"; const app = express() +//解决跨域 +app.use((req, res, next) => { + // 设置是否运行客户端设置 withCredentials + // 即在不同域名下发出的请求也可以携带 cookie + res.header("Access-Control-Allow-Credentials", true) + // 第二个参数表示允许跨域的域名,* 代表所有域名 + res.header('Access-Control-Allow-Origin', '*')//配置80端口跨域 + res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, OPTIONS') // 允许的 http 请求的方法 + // 允许前台获得的除 Cache-Control、Content-Language、Content-Type、Expires、Last-Modified、Pragma 这几张基本响应头之外的响应头 + res.header('Access-Control-Allow-Headers', '*') + if (req.method == 'OPTIONS') { + res.sendStatus(200) + } else { + next() + } +}) + app.use('/v1/api/tag', tagsRouter); app.use('/v1/api/info', infoRouter); app.use('/v1/api/search', searchRouter); diff --git a/newBackApi/package.json b/newBackApi/package.json index ad5d768..640ab94 100644 --- a/newBackApi/package.json +++ b/newBackApi/package.json @@ -5,7 +5,8 @@ "main": "index.js", "type": "module", "scripts": { - "dev": "node-dev app.js" + "dev": "node-dev app.js", + "": " apidoc -i router/ -o doc/" }, "keywords": [], "author": "", diff --git a/newBackApi/router/search.js b/newBackApi/router/search.js index e2c48be..9be8f4c 100644 --- a/newBackApi/router/search.js +++ b/newBackApi/router/search.js @@ -36,15 +36,15 @@ router.get('/hot', async (req, res) => { // 搜索接口 -// http://192.168.31.101:3030/v1/api/search?keyword=杨晨晨 -router.get('/', async (req, res) => { +// http://192.168.31.101:3030/v1/api/search/key?keyword=杨晨晨&page=1 +router.get('/key', async (req, res) => { let { keyword, page } = req.query page = page || 1 let $ = await Util.get(`${Config.baseUrl}/page/${page}?s=${encodeURI(keyword)}&type=post`) let result = { currentPage: page, - totalPage: $(".pagenav a").eq(2).text(), + totalPage: Number($(".pagenav a").eq(1).text()), message: $(".search-content .badg .focus-color").text(), list: [], } diff --git a/newBackApi/router/tags.js b/newBackApi/router/tags.js index 6619d04..03f996b 100644 --- a/newBackApi/router/tags.js +++ b/newBackApi/router/tags.js @@ -4,7 +4,22 @@ import Config from '../config/config.js' const router = express.Router(); -// 获取 热门标签 +// 获取 推荐标签 +// http://192.168.31.101:3030/v1/api/tag/recommend +router.get('/recommend', async (req, res) => { + res.json({ + status: 200, + copyright: `bmy ${new Date()}`, + data: [ + { title: '秀人网', count: '9059', url: '/xiuren' }, + { title: 'ROSI写真', count: '6580', url: '/domestic/rosi' }, + { title: '蜜桃社', count: '122', url: '/domestic/miitao' }, + { title: '尤物馆', count: '138', url: '/domestic/youwu' }, + ] + }); +}) + +// 获取 所有标签 // http://192.168.31.101:3030/v1/api/tag/list router.get('/list', async (req, res) => { let $ = await Util.get(Config.hot_tags()) diff --git a/newBackApi/utils/index.js b/newBackApi/utils/index.js index cb61331..ae06594 100644 --- a/newBackApi/utils/index.js +++ b/newBackApi/utils/index.js @@ -35,10 +35,14 @@ class utils { async get(url) { return await this.ax.get(url, { headers: { - 'cookie': `_ga=GA1.1.2076335189.1731510827; history_search=%5B%22%5Cu6768%5Cu6668%5Cu6668%26type%3Dpost%22%2C%22%5Cu767d%5Cu4e1d%26type%3Dpost%22%2C%22jk%26type%3Dpost%22%5D; PHPSESSID=22oh5maqqirjstqs1p7gbtome7; _lscache_vary=0e8aace2958628a1edb01710bbabbcab; showed_system_notice=showed; _ga_ZT9Q6FCC5R=GS1.1.1732278002.10.1.1732278777.0.0.0`, - 'referer': 'https://www.06se.com/', - 'user-agent': `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36`, - 'accept': `text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7` + 'sec-ch-ua-mobile': '?1', + 'sec-fetch-site': 'same-origin', + 'upgrade-insecure-requests': '1', + 'priority': 'u=0, i', + 'sec-fetch-mode': 'navigate', + 'cookie': `_ga=GA1.1.1571194344.1732275775; _lscache_vary=0e8aace2958628a1edb01710bbabbcab; showed_system_notice=showed; PHPSESSID=5jmev023fsh6i76huat60njio3; _ga_ZT9Q6FCC5R=GS1.1.1732668048.9.1.1732668791.0.0.0`, + 'referer': 'https://www.06se.com/hot_tags', + 'user-agent': `Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1` } }); }