Dotos 8 tahun lalu
induk
melakukan
ae622945d7
3 mengubah file dengan 7 tambahan dan 1 penghapusan
  1. 1 1
      app.js
  2. 5 0
      routes/netease.js
  3. 1 0
      utils/util.js

+ 1 - 1
app.js

@@ -37,7 +37,7 @@ app.disable('x-powered-by');
 // }));
 //app.use(bodyParser.raw({ type: '*/*' }));
 app.use(function(req, res, next) {
-    // 设置跨域头
+    // 设置跨域头 ************** 本地使用时请去掉以下3行的注释
     // res.header("Access-Control-Allow-Origin", "*");
     // res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Access-Control-Allow-Origin");
     // res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");

+ 5 - 0
routes/netease.js

@@ -11,6 +11,8 @@ const links = {
 
 /* GET users listing. */
 router.get('/:channel', function(req, res, next) {
+
+    let ip = req.ip.replace('::1', '127.0.0.1')
     const id = req.query.id
     const br = req.query.br || 999000
     const channel = req.params['channel']
@@ -20,6 +22,9 @@ router.get('/:channel', function(req, res, next) {
             "ids": [id],
             "br": 999000,
             "csrf_token": ""
+        },
+        headers: {
+            'X-Real-IP': ip
         }
     }
     switch (channel) {

+ 1 - 0
utils/util.js

@@ -18,6 +18,7 @@ let options = {
 const requestServer = (config) => {
     options['uri'] = `http://music.163.com${config.path}`
     options['form'] = encrypt(config.params)
+    options['headers']['X-Real-IP'] = config['headers']['X-Real-IP'] || '127.0.0.1'
     return new Promise((resolve, reject) => {
         request(options, (err, ret, body) => {
             if (!err && ret.statusCode === 200) {