File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ module . exports = {
2+ devServer : {
3+ compress : true ,
4+ port : 9000 ,
5+ host : "0.0.0.0" ,
6+ historyApiFallback : true ,
7+ hot : true ,
8+ inline : true ,
9+ open : true ,
10+ before : function ( app ) {
11+ const path = require ( "path" ) ;
12+ const glob = require ( "glob" ) ;
13+ const mockApiData = getMockApiData ( ) ;
14+ Object . keys ( mockApiData ) . forEach ( item => {
15+ app . all ( `/api${ item } ` , function ( req , res ) {
16+ setTimeout ( ( ) => {
17+ res . json ( mockApiData [ item ] ) ;
18+ } , 1000 ) ;
19+ } ) ;
20+ } ) ;
21+
22+ function getMockApiData ( ) {
23+ let mockPaths = glob . sync ( "**/__mock__/**/*.json" , {
24+ cwd : path . resolve ( __dirname , "./src" )
25+ } ) ;
26+ let mockApiData = { } ;
27+ mockPaths . forEach ( mockPath => {
28+ console . log ( mockPath ) ;
29+ const fileIndex = / ^ _ _ m o c k _ _ ( .+ ) \. j s o n / . exec ( mockPath ) [ 1 ] ;
30+ const filepath = path . resolve (
31+ path . resolve ( __dirname , "./src" ) ,
32+ mockPath
33+ ) ;
34+ mockApiData [ fileIndex ] = require ( filepath ) ;
35+ } ) ;
36+ return mockApiData ;
37+ }
38+ }
39+ }
40+ } ;
You can’t perform that action at this time.
0 commit comments