@@ -48,7 +48,7 @@ function findMock(config, req) {
4848 params,
4949 query,
5050 type,
51- error : mockPath ? false : constants [ 'error.not-found' ]
51+ error : mockPath . path ? false : constants [ 'error.not-found' ]
5252 } ;
5353}
5454
@@ -91,73 +91,6 @@ function findMockPath(filePath, req, config) {
9191 }
9292}
9393
94- function findFile ( config , req ) {
95- var filePath ,
96- defaultFilePath ,
97- error = false ,
98- method = '.' + ( req . method || '' ) . toLowerCase ( ) ,
99- path ,
100- type ;
101-
102- if ( req . params ) {
103- filePath = config . mocks + '/' + req . params [ 0 ] ;
104- } else {
105- filePath = config [ 'conf-folder' ] + config [ 'info-file' ] ;
106- }
107- defaultFilePath = filePath . substr ( 0 , filePath . lastIndexOf ( '/' ) ) + '/' + constants [ 'file.name.default' ] ;
108-
109- if ( fs . existsSync ( filePath + method + constants [ 'file.ext:code' ] ) ) {
110- path = filePath + method + constants [ 'file.ext:code' ] ;
111- type = constants [ 'content.code' ] ;
112- } else if ( fs . existsSync ( filePath + method + constants [ 'file.ext:data' ] ) ) {
113- path = filePath + method + constants [ 'file.ext:data' ] ;
114- type = constants [ 'content.data' ] ;
115- } else if ( fs . existsSync ( filePath + constants [ 'file.ext:code' ] ) ) {
116- path = filePath + constants [ 'file.ext:code' ] ;
117- type = constants [ 'content.code' ] ;
118- } else if ( fs . existsSync ( filePath + constants [ 'file.ext:data' ] ) ) {
119- path = filePath + constants [ 'file.ext:data' ] ;
120- type = constants [ 'content.data' ] ;
121- } else if ( fs . existsSync ( defaultFilePath + method + constants [ 'file.ext:code' ] ) ) {
122- path = defaultFilePath + method + constants [ 'file.ext:code' ] ;
123- type = constants [ 'content.code' ] ;
124- } else if ( fs . existsSync ( defaultFilePath + method + constants [ 'file.ext:data' ] ) ) {
125- path = defaultFilePath + method + constants [ 'file.ext:data' ] ;
126- type = constants [ 'content.data' ] ;
127- } else if ( fs . existsSync ( defaultFilePath + constants [ 'file.ext:code' ] ) ) {
128- path = defaultFilePath + constants [ 'file.ext:code' ] ;
129- type = constants [ 'content.code' ] ;
130- } else if ( fs . existsSync ( defaultFilePath + constants [ 'file.ext:data' ] ) ) {
131- path = defaultFilePath + constants [ 'file.ext:data' ] ;
132- type = constants [ 'content.data' ] ;
133- } else {
134- error = constants [ 'error.not-found' ] ;
135- }
136-
137- return {
138- error : error ,
139- path : path ,
140- type : type
141- } ;
142- }
143-
144- function openFile ( config , req ) {
145- let fileInfo = findFile ( config , req ) ;
146-
147- if ( fileInfo . error ) return fileInfo ;
148-
149- fileInfo . content = fs . readFileSync ( fileInfo . path ) ;
150- if ( fileInfo . type === constants [ 'content.code' ] ) {
151- fileInfo . context = {
152- req : req ,
153- params : req . params ,
154- query : req . query ,
155- mock : false
156- } ;
157- }
158- return fileInfo ;
159- }
160-
16194function openMock ( config , req ) {
16295 let fileInfo = findMock ( config , req ) ;
16396
@@ -193,23 +126,12 @@ function parseFile(file) {
193126 return JSON . parse ( JSON . stringify ( response ) ) ;
194127}
195128
196- function getFile ( config , req ) {
197- return parseFile ( openFile ( config , req ) ) ;
198- }
199129
200130function getMock ( config , req ) {
201131 return parseFile ( openMock ( config , req ) ) ;
202132}
203133
204- function getInfo ( config ) {
205- return getFile ( config , {
206- path : ( config [ 'conf-folder' ] + config [ 'info-file' ] )
207- } ) ;
208- }
209-
210134// Exports
211135module . exports = {
212- getFile,
213- getInfo,
214136 getMock
215137} ;
0 commit comments