提交 f965e771 编写于 作者: Q qq_41923622

Mon Feb 10 13:22:00 CST 2025 inscode

上级 d8233280
// app.js
const express = require('express'); const express = require('express');
const bodyParser = require('body-parser'); const { createProxyMiddleware } = require('http-proxy-middleware');
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;
if (!texts[id]) { const app = express();
return res.status(404).send({ error: 'Text not found' }); const port = 3001;
}
// 目标服务器地址
res.send({ id, text: texts[id] }); const targetUrl = 'http://s.hunlihu.com';
});
// 创建代理中间件
// Update a specific text entry by ID const apiProxy = createProxyMiddleware('/', {
app.put('/api/text/:id', (req, res) => { target: targetUrl,
const { id } = req.params; changeOrigin: true,
const newText = req.body.text; pathRewrite: {
'^/': '' // 重写请求路径
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 });
}); });
// Delete a specific text entry by ID // 使用代理中间件
app.delete('/api/text/:id', (req, res) => { app.use(apiProxy);
const { id } = req.params;
if (!texts[id]) { app.listen(port, () => {
return res.status(404).send({ error: 'Text not found' }); console.log(`Server is running on port ${port}`);
} });
\ No newline at end of file
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}`));
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册