11//引入express中间件
2- var express = require ( 'express' ) ;
3- var compression = require ( 'compression' ) ;
2+ let express = require ( 'express' ) ;
3+ let compression = require ( 'compression' ) ;
44let axios = require ( 'axios' ) ;
55const http = require ( 'http' ) ;
6- var bodyParser = require ( "body-parser" ) ;
6+ let bodyParser = require ( "body-parser" ) ;
7+ let fromUrl = '' ;
78
89var app = express ( ) ;
910app . use ( compression ( ) ) ;
@@ -13,6 +14,7 @@ http.createServer(app).listen(67);
1314
1415app . get ( '/' , ( req , res ) => {
1516 res . sendFile ( 'index.html' , { root : __dirname } ) ;
17+ fromUrl = req . headers [ 'referer' ] ;
1618} ) ;
1719
1820app . get ( '/*' , ( req , res ) => {
@@ -28,14 +30,15 @@ app.post('/*', (req, res) => {
2830
2931 // 转发时带着原请求的ip信息
3032 req . body . clientIp = clientIp . replace ( '::ffff:' , '' ) ;
33+ req . body . fromUrl = fromUrl ;
3134
3235 axios . post (
3336 'http://39.104.22.73:8888' + pathName . replace ( 'api' , '' ) ,
3437 req . body
3538 ) . then ( function ( response ) {
3639 res . end ( JSON . stringify ( response . data ) ) ;
3740 } ) . catch ( function ( e ) {
38- console . log ( 'ajax error' ) ;
41+ console . log ( '转发 ajax error' ) ;
3942 } ) ;
4043} ) ;
4144
0 commit comments