@@ -136,7 +136,7 @@ var rules = {
136136} ;
137137
138138var getInfo = function ( req , option , headers ) {
139- var url = req . _parsedUrl . pathname . replace ( / ^ \/ / , '' ) ;
139+ var url = req . _parsedUrl [ / g e t / i . test ( req . method ) ? ' pathname' : 'href' ] . replace ( / ^ \/ / , '' ) ;
140140 return {
141141 url : url ,
142142 data : option . mockData [ url ] ,
@@ -176,8 +176,9 @@ var middlewares = jsonServer.defaults({
176176 static : path . resolve ( __dirname , './public' )
177177} ) ;
178178server$1 . use ( middlewares ) ;
179- var createServer = function ( option ) {
179+ var createServer = function ( option , callback ) {
180180 var config = option . https ;
181+ config = / ^ ( b o o l e a n | n u m b e r ) $ / . test ( typeof config ) ? config && { } : config ;
181182 if ( config instanceof Object ) {
182183 if ( typeof config . key !== 'string' || typeof config . cert !== 'string' || config . key . length + config . cert . length === 0 ) {
183184 config . key = fs . readFileSync ( path . join ( __dirname , 'ssl/key.pem' ) ) ;
@@ -188,13 +189,15 @@ var createServer = function (option) {
188189 console . log ( ) ;
189190 console . log ( "\u5DF2\u542F\u52A8json-server\u670D\u52A1\u5668 https://localhost:" + option . port ) ;
190191 console . log ( ) ;
192+ typeof callback == 'function' && callback ( ) ;
191193 } ) ;
192194 }
193195 else {
194196 server$1 . listen ( option . port , function ( ) {
195197 console . log ( ) ;
196198 console . log ( "\u5DF2\u542F\u52A8json-server\u670D\u52A1\u5668 http://localhost:" + option . port ) ;
197199 console . log ( ) ;
200+ typeof callback == 'function' && callback ( ) ;
198201 } ) ;
199202 }
200203} ;
@@ -207,7 +210,7 @@ var createServer = function (option) {
207210 * @param {boolean= } option.crossDomain - 是否跨域 (便于在不设置请求头时, 快速配置跨域)
208211 * @param {number= } port - 服务器端口
209212 */
210- var Server$1 = function ( option ) {
213+ var Server$1 = function ( option , callback ) {
211214 option = Object . assign ( {
212215 port : 3030 ,
213216 crossDomain : true ,
@@ -274,6 +277,17 @@ var Server$1 = function (option) {
274277 if ( ! Array . isArray ( relay ) ) {
275278 relay = [ relay ] ;
276279 }
280+ if ( relay . length ) {
281+ if ( ! / ( h t t p ( s ) | \/ \/ ) / . test ( relay [ 0 ] ) ) {
282+ var protocol = req . headers . referer . split ( ':' ) [ 0 ] + ':' ;
283+ if ( typeof relay [ 0 ] == 'string' ) {
284+ relay [ 0 ] = protocol + '//' + ( req . headers . host + relay [ 0 ] ) . replace ( / \/ + / g, '/' ) ;
285+ }
286+ else if ( relay [ 0 ] instanceof Object ) {
287+ relay [ 0 ] . url = protocol + '//' + ( req . headers . host + relay [ 0 ] . url ) . replace ( / \/ + / g, '/' ) ;
288+ }
289+ }
290+ }
277291 request . apply ( request , relay . concat ( function ( error , response , body ) {
278292 if ( ! error ) {
279293 try {
@@ -300,6 +314,7 @@ var Server$1 = function (option) {
300314 code : 400 ,
301315 message : "请求失败"
302316 } ) ;
317+ console . log ( error ) ;
303318 }
304319 } ) ) ;
305320 return ;
@@ -364,7 +379,7 @@ var Server$1 = function (option) {
364379 res . status ( 200 ) . jsonp ( body ) ;
365380 } ;
366381 server$1 . use ( router ) ;
367- createServer ( option ) ;
382+ createServer ( option , callback ) ;
368383} ;
369384
370385/**
0 commit comments