-
Notifications
You must be signed in to change notification settings - Fork 0
/
win.server.js
executable file
·80 lines (70 loc) · 2.28 KB
/
win.server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const express = require('express')
const app = express()
const superagent = require('superagent')
const bodyParser = require('body-parser');
// const target = 'http://www.yhcqp.com'
const target = 'http://yhcqp.youfan.pub'
let cookie = ''
superagent
.post(target + '/community/login')
.send({username: '18868432772', password: 'aa123456'})
// .post(target + '/community/login?username=15601843755&password=799395')
.end((err, res) => {
if(res.body.code === 1) console.log('登录成功')
// 获取 Cookie, beta 处理有问题, 需要如下处理才能登陆
cookie = res.header['set-cookie'].toString()
cookie = cookie.replace(/(Path=\/),/g, '$1;') // 莫名的一个逗号, 需要处理成 ';'
})
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static(__dirname))
app.get('/*', (req, res) => {
agentGet(req, res)
})
app.post('/*', (req, res) => {
agentPost(req, res)
})
app.delete('/*', (req, res) => {
agentDelete(req, res)
})
function agentPost(req, res) {
superagent
.post(target + req.url)
.set('Content-Type', 'application/json;charset=UTF-8')
.set('Cookie', cookie)
.send(req.body)
.end((err, sRes) => {
if(sRes.body.code !== 1) console.log(sRes.body)
// console.log(sRes.body)
res.set('Content-Type', 'application/json');
res.send(JSON.stringify(Object.assign(sRes.body, { isLocal: true })))
})
}
function agentGet(req, res) {
superagent
.get(target + req.url)
.set('Content-Type', 'application/json;charset=UTF-8')
.set('Cookie', cookie)
.send(req.query)
.end((err, sRes) => {
// console.log(sRes.body)
res.set('Content-Type', 'application/json');
res.send(JSON.stringify(Object.assign(sRes.body, { isLocal: true })))
})
}
function agentDelete(req, res) {
superagent
.delete(target + req.url)
.set('Content-Type', 'application/json;charset=UTF-8')
.set('Cookie', cookie)
.send(req.body)
.end((err, sRes) => {
// console.log(sRes.body)
res.set('Content-Type', 'application/json');
res.send(JSON.stringify(Object.assign(sRes.body, { isLocal: true })))
})
}
app.listen(8888, 'localhost', (err) => {
if(err) console.log(err)
else console.log('run on localhost:8888')
})