@@ -9,18 +9,18 @@ var Mock = _interopDefault(require('mockjs'));
99var fs = require ( 'fs' ) ;
1010
1111/*! *****************************************************************************
12- Copyright (c) Microsoft Corporation. All rights reserved.
13- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
14- this file except in compliance with the License. You may obtain a copy of the
15- License at http://www.apache.org/licenses/LICENSE-2.0
12+ Copyright (c) Microsoft Corporation.
1613
17- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
19- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
20- MERCHANTABLITY OR NON-INFRINGEMENT.
14+ Permission to use, copy, modify, and/or distribute this software for any
15+ purpose with or without fee is hereby granted.
2116
22- See the Apache Version 2.0 License for specific language governing permissions
23- and limitations under the License.
17+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23+ PERFORMANCE OF THIS SOFTWARE.
2424***************************************************************************** */
2525/* global Reflect, Promise */
2626
@@ -170,6 +170,12 @@ var Http = /** @class */ (function () {
170170 } ;
171171 return Http ;
172172} ( ) ) ;
173+ var noop = function ( func ) {
174+ if ( typeof func === 'function' ) {
175+ return func ;
176+ }
177+ return function ( ) { } ;
178+ } ;
173179var getInfo = function ( req , option , headers ) {
174180 var url = req . _parsedUrl [ / g e t / i. test ( req . method ) ? 'pathname' : 'href' ] . replace ( / ^ \/ / , '' ) ;
175181 return {
@@ -335,15 +341,20 @@ var methodHandler = function (_a, next) {
335341var server$1 = jsonServer . create ( ) ;
336342// 路径从根目录开始?
337343var router = jsonServer . router ( path . resolve ( process . cwd ( ) , 'db.json' ) ) ;
338- var middlewares = jsonServer . defaults ( {
339- static : path . resolve ( __dirname , './public' )
340- } ) ;
341- server$1 . use ( middlewares ) ;
342344var createServer = function ( option , callback ) {
343345 var config = option . https ;
344346 config = / ^ ( b o o l e a n | n u m b e r ) $ / . test ( typeof config ) ? config && { } : config ;
345347 var currentServer ;
346348 if ( config instanceof Object ) {
349+ if ( typeof config . static === 'function' ) {
350+ config . static ( jsonServer , server$1 ) ;
351+ }
352+ else {
353+ var middlewares = jsonServer . defaults ( {
354+ static : typeof config . static === 'string' ? config . static : path . resolve ( process . cwd ( ) , './public' )
355+ } ) ;
356+ server$1 . use ( middlewares ) ;
357+ }
347358 if ( typeof config . key !== 'string' || typeof config . cert !== 'string' || config . key . length + config . cert . length === 0 ) {
348359 config . key = fs . readFileSync ( path . join ( __dirname , 'ssl/key.pem' ) ) ;
349360 config . cert = fs . readFileSync ( path . join ( __dirname , 'ssl/cert.pem' ) ) ;
@@ -397,6 +408,9 @@ var Server$1 = function (option, callback) {
397408 // 路由映射
398409 server$1 . use ( jsonServer . rewriter ( option . rules instanceof Object ? option . rules : rules ) ) ;
399410 server$1 . use ( function ( req , res , next ) {
411+ if ( noop ( option . interceptor ) ( req , res , next ) === false ) {
412+ return ;
413+ }
400414 var http = new Http ( res ) ;
401415 var _a = getInfo ( req , option , config$1 . crossDomain ) , url = _a . url , data = _a . data , method = _a . method , urlKey = _a . urlKey , params = _a . params , headConfig = _a . headConfig ;
402416 var result = { } ;
0 commit comments