From f965e771deb2f9b51e09b97b47887ded0adca6d0 Mon Sep 17 00:00:00 2001 From: qq_41923622 Date: Mon, 10 Feb 2025 13:22:00 +0800 Subject: [PATCH] Mon Feb 10 13:22:00 CST 2025 inscode --- index.js | 115 +++++++++------------------------------------------ package.json | 1 + 2 files changed, 20 insertions(+), 96 deletions(-) diff --git a/index.js b/index.js index aba701f..21997f6 100644 --- a/index.js +++ b/index.js @@ -1,101 +1,24 @@ -// app.js - const express = require('express'); -const bodyParser = require('body-parser'); -var FormData = require('form-data'); -const request = require('request'); -const app = express(); -app.use(bodyParser.json()); - -let texts = {}; // In-memory storage for texts - -// Create a new text entry -app.post('/api/text', (req, res) => { - const id = Date.now().toString(); // Simple unique ID generation - const text = req.body.text; - - if (!text || typeof text !== 'string') { - return res.status(400).send({ error: 'Invalid or missing text' }); - } - - texts[id] = text; - res.send({ id, text }); -}); - -// Get all text entries -app.get('/api/texts', (req, res) => { - res.send(Object.entries(texts).map(([id, text]) => ({ id, text }))); -}); - -// Get a specific text entry by ID -app.get('/api/text/:id', (req, res) => { - const { id } = req.params; +const { createProxyMiddleware } = require('http-proxy-middleware'); - if (!texts[id]) { - return res.status(404).send({ error: 'Text not found' }); - } - - res.send({ id, text: texts[id] }); -}); - -// Update a specific text entry by ID -app.put('/api/text/:id', (req, res) => { - const { id } = req.params; - const newText = req.body.text; - - if (!newText || typeof newText !== 'string') { - return res.status(400).send({ error: 'Invalid or missing text' }); - } - - if (!texts[id]) { - return res.status(404).send({ error: 'Text not found' }); - } - - texts[id] = newText; - res.send({ id, text: newText }); +const app = express(); +const port = 3001; + +// 目标服务器地址 +const targetUrl = 'http://s.hunlihu.com'; + +// 创建代理中间件 +const apiProxy = createProxyMiddleware('/', { + target: targetUrl, + changeOrigin: true, + pathRewrite: { + '^/': '' // 重写请求路径 + } }); -// Delete a specific text entry by ID -app.delete('/api/text/:id', (req, res) => { - const { id } = req.params; +// 使用代理中间件 +app.use(apiProxy); - if (!texts[id]) { - return res.status(404).send({ error: 'Text not found' }); - } - - delete texts[id]; - res.sendStatus(204); -}); - var headersData = { - "Accept-Encoding": "gzip, deflate, br", - "Accept-Language": "zh-CN,zh;q=0.9", - Connection: "keep-alive", - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", - Host: "h5.hunlihu.com", - Origin: "https://s.hunlihu.com", - Referer: "https://s.hunlihu.com/", - "sec-ch-ua": "\".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"", - "sec-ch-ua-mobile": "?0", - "sec-ch-ua-platform": "Windows", - "Sec-Fetch-Dest": "empty", - "Sec-Fetch-Mode": "cors", - "Sec-Fetch-Site": "same-site", - "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.66 Safari/537.36", - }; - const formData = new FormData(); - formData.append('auth', 'Lz8rzL8zzt'); - formData.append('jsons', `[{"d_name":"five","user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.66 Safari/537.36","msg_type":"1","openid":"","nickname":"哈哈","headimgurl":"","d_else":"fiveasdasd"}]`); - request( { - method: 'POST', // 指定请求方法为 POST - headers: headersData, - formData: { - 'auth': 'Lz8rzL8zzt', - 'jsons': `[{"d_name":"five","user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.66 Safari/537.36","msg_type":"1","openid":"","nickname":"哈哈","headimgurl":"","d_else":"fiveasdasd"}]` - }, - url: 'https://h5.hunlihu.com/vashow/ly/door/door/sign2', - },(error, response, body)=>{ - if (!error && response.statusCode == 200) {} - console.log(`error, response, body`,error, response, body) -}) -const PORT = process.env.PORT || 3000; -app.listen(PORT, () => console.log(`Server running on port ${PORT}`)); +app.listen(port, () => { + console.log(`Server is running on port ${port}`); +}); \ No newline at end of file diff --git a/package.json b/package.json index f012221..e55eae9 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "body-parser": "^1.20.3", "express": "^4.21.2", "form-data": "^4.0.1", + "http-proxy-middleware": "^3.0.3", "node-fetch": "^3.2.6", "request": "^2.88.2" } -- GitLab