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
- }
7
1
export namespace mock {
8
2
9
3
interface anyObject < T = any > {
@@ -29,6 +23,8 @@ export namespace mock {
29
23
crossDomain ?: boolean ;
30
24
// 端口号
31
25
port ?: number ;
26
+ // 静态文件目录
27
+ static ?: string | ( ( jsonServer : Object , server : Object ) => void ) ;
32
28
// https证书配置
33
29
https ?: {
34
30
key : string ;
@@ -64,4 +60,11 @@ export namespace mock {
64
60
}
65
61
) => undefined | object | string | Function ;
66
62
}
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
+
67
70
export default KsMock
Original file line number Diff line number Diff line change @@ -10,16 +10,20 @@ import { mock } from '../';
10
10
const server = jsonServer . create ( )
11
11
// 路径从根目录开始?
12
12
const router = jsonServer . router ( path . resolve ( process . cwd ( ) , 'db.json' ) )
13
- const middlewares = jsonServer . defaults ( {
14
- static : path . resolve ( __dirname , './public' )
15
- } )
16
13
17
- server . use ( middlewares )
18
14
const createServer = ( option : mock . anyObject , callback ?: Function ) => {
19
15
let config = option . https
20
16
config = / ^ ( b o o l e a n | n u m b e r ) $ / . test ( typeof config ) ? config && { } : config
21
17
let currentServer
22
18
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
+ }
23
27
if ( typeof config . key !== 'string' || typeof config . cert !== 'string' || config . key . length + config . cert . length === 0 ) {
24
28
config . key = fs . readFileSync ( path . join ( __dirname , 'ssl/key.pem' ) )
25
29
config . cert = fs . readFileSync ( path . join ( __dirname , 'ssl/cert.pem' ) )
You can’t perform that action at this time.
0 commit comments