mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-05-23 22:37:41 +08:00
客户端ip传入完善
This commit is contained in:
parent
1591d0df6f
commit
e174de0448
1
app.js
1
app.js
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
const generateConfig = require('./generateConfig')
|
||||
async function start() {
|
||||
// 如果需要手动修改anonymous_token,需要注释generateConfig调用
|
||||
await generateConfig()
|
||||
require('./server').serveNcmApi({
|
||||
checkVersion: true,
|
||||
|
16
server.js
16
server.js
@ -219,7 +219,21 @@ async function consturctServer(moduleDefs) {
|
||||
)
|
||||
|
||||
try {
|
||||
const moduleResponse = await moduleDef.module(query, request)
|
||||
const moduleResponse = await moduleDef.module(query, (...params) => {
|
||||
// 参数注入客户端IP
|
||||
const obj = [...params]
|
||||
let ip = req.ip
|
||||
|
||||
if (ip.substr(0, 7) == '::ffff:') {
|
||||
ip = ip.substr(7)
|
||||
}
|
||||
// console.log(ip)
|
||||
obj[3] = {
|
||||
...obj[3],
|
||||
ip,
|
||||
}
|
||||
return request(...obj)
|
||||
})
|
||||
console.log('[OK]', decode(req.originalUrl))
|
||||
|
||||
const cookies = moduleResponse.cookie
|
||||
|
@ -6,7 +6,6 @@ const https = require('https')
|
||||
const tunnel = require('tunnel')
|
||||
const { URLSearchParams, URL } = require('url')
|
||||
const config = require('../util/config.json')
|
||||
const { getRandom } = require('../util')
|
||||
// request.debug = true // 开启可看到更详细信息
|
||||
|
||||
const chooseUserAgent = (ua = false) => {
|
||||
@ -50,7 +49,12 @@ const createRequest = (method, url, data = {}, options) => {
|
||||
headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
||||
if (url.includes('music.163.com'))
|
||||
headers['Referer'] = 'https://music.163.com'
|
||||
if (options.realIP) headers['X-Real-IP'] = options.realIP
|
||||
let ip = options.realIP || options.ip || ''
|
||||
// console.log(ip)
|
||||
if (ip) {
|
||||
headers['X-Real-IP'] = ip
|
||||
headers['X-Forwarded-For'] = ip
|
||||
}
|
||||
// headers['X-Real-IP'] = '118.88.88.88'
|
||||
if (typeof options.cookie === 'object') {
|
||||
if (!options.cookie.MUSIC_U) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user