File tree Expand file tree Collapse file tree 2 files changed +17
-10
lines changed Expand file tree Collapse file tree 2 files changed +17
-10
lines changed Original file line number Diff line number Diff line change 1- export declare class KsMock {
2- public option : mock . options ;
3- constructor ( option : mock . options ) ;
4- public apply ( compiler : any ) : void ;
5- public server ( option ?: mock . options ) : void ;
6- }
71export namespace mock {
82
93 interface anyObject < T = any > {
@@ -29,6 +23,8 @@ export namespace mock {
2923 crossDomain ?: boolean ;
3024 // 端口号
3125 port ?: number ;
26+ // 静态文件目录
27+ static ?: string | ( ( jsonServer : Object , server : Object ) => void ) ;
3228 // https证书配置
3329 https ?: {
3430 key : string ;
@@ -64,4 +60,11 @@ export namespace mock {
6460 }
6561 ) => undefined | object | string | Function ;
6662}
63+ export declare class KsMock {
64+ public option : mock . options ;
65+ constructor ( option : mock . options ) ;
66+ public apply ( compiler : any ) : void ;
67+ public server ( option ?: mock . options ) : void ;
68+ }
69+
6770export default KsMock
Original file line number Diff line number Diff line change @@ -10,16 +10,20 @@ import { mock } from '../';
1010const server = jsonServer . create ( )
1111// 路径从根目录开始?
1212const router = jsonServer . router ( path . resolve ( process . cwd ( ) , 'db.json' ) )
13- const middlewares = jsonServer . defaults ( {
14- static : path . resolve ( __dirname , './public' )
15- } )
1613
17- server . use ( middlewares )
1814const createServer = ( option : mock . anyObject , callback ?: Function ) => {
1915 let config = option . https
2016 config = / ^ ( b o o l e a n | n u m b e r ) $ / . test ( typeof config ) ? config && { } : config
2117 let currentServer
2218 if ( config instanceof Object ) {
19+ if ( typeof config . static === 'function' ) {
20+ config . static ( jsonServer , server )
21+ } else {
22+ const middlewares = jsonServer . defaults ( {
23+ static : typeof config . static === 'string' ? config . static : path . resolve ( process . cwd ( ) , './public' )
24+ } )
25+ server . use ( middlewares )
26+ }
2327 if ( typeof config . key !== 'string' || typeof config . cert !== 'string' || config . key . length + config . cert . length === 0 ) {
2428 config . key = fs . readFileSync ( path . join ( __dirname , 'ssl/key.pem' ) )
2529 config . cert = fs . readFileSync ( path . join ( __dirname , 'ssl/cert.pem' ) )
You can’t perform that action at this time.
0 commit comments