mock-js-server
Advanced tools
Comparing version 0.0.11 to 0.0.12
{ | ||
"^$": "../config/info.json", | ||
"^/$": "../config/info.json", | ||
"cached": "cached.json", | ||
".*logs/{{param1}}/{{param2}}": "user/default.js" | ||
} |
@@ -51,3 +51,3 @@ 'use strict'; | ||
type, | ||
error: mockPath ? false : constants['error.not-found'] | ||
error: mockPath.path ? false : constants['error.not-found'] | ||
}; | ||
@@ -95,69 +95,2 @@ } | ||
function findFile(config, req) { | ||
var filePath, | ||
defaultFilePath, | ||
error = false, | ||
method = '.' + (req.method || '').toLowerCase(), | ||
path, | ||
type; | ||
if (req.params) { | ||
filePath = config.mocks + '/' + req.params[0]; | ||
} else { | ||
filePath = config['conf-folder'] + config['info-file']; | ||
} | ||
defaultFilePath = filePath.substr(0, filePath.lastIndexOf('/')) + '/' + constants['file.name.default']; | ||
if (fs.existsSync(filePath + method + constants['file.ext:code'])) { | ||
path = filePath + method + constants['file.ext:code']; | ||
type = constants['content.code']; | ||
} else if (fs.existsSync(filePath + method + constants['file.ext:data'])) { | ||
path = filePath + method + constants['file.ext:data']; | ||
type = constants['content.data']; | ||
} else if (fs.existsSync(filePath + constants['file.ext:code'])) { | ||
path = filePath + constants['file.ext:code']; | ||
type = constants['content.code']; | ||
} else if (fs.existsSync(filePath + constants['file.ext:data'])) { | ||
path = filePath + constants['file.ext:data']; | ||
type = constants['content.data']; | ||
} else if (fs.existsSync(defaultFilePath + method + constants['file.ext:code'])) { | ||
path = defaultFilePath + method + constants['file.ext:code']; | ||
type = constants['content.code']; | ||
} else if (fs.existsSync(defaultFilePath + method + constants['file.ext:data'])) { | ||
path = defaultFilePath + method + constants['file.ext:data']; | ||
type = constants['content.data']; | ||
} else if (fs.existsSync(defaultFilePath + constants['file.ext:code'])) { | ||
path = defaultFilePath + constants['file.ext:code']; | ||
type = constants['content.code']; | ||
} else if (fs.existsSync(defaultFilePath + constants['file.ext:data'])) { | ||
path = defaultFilePath + constants['file.ext:data']; | ||
type = constants['content.data']; | ||
} else { | ||
error = constants['error.not-found']; | ||
} | ||
return { | ||
error: error, | ||
path: path, | ||
type: type | ||
}; | ||
} | ||
function openFile(config, req) { | ||
let fileInfo = findFile(config, req); | ||
if (fileInfo.error) return fileInfo; | ||
fileInfo.content = fs.readFileSync(fileInfo.path); | ||
if (fileInfo.type === constants['content.code']) { | ||
fileInfo.context = { | ||
req: req, | ||
params: req.params, | ||
query: req.query, | ||
mock: false | ||
}; | ||
} | ||
return fileInfo; | ||
} | ||
function openMock(config, req) { | ||
@@ -198,5 +131,2 @@ let fileInfo = findMock(config, req); | ||
function getFile(config, req) { | ||
return parseFile(openFile(config, req)); | ||
} | ||
@@ -207,13 +137,5 @@ function getMock(config, req) { | ||
function getInfo(config) { | ||
return getFile(config, { | ||
path: (config['conf-folder'] + config['info-file']) | ||
}); | ||
} | ||
// Exports | ||
module.exports = { | ||
getFile, | ||
getInfo, | ||
getMock | ||
}; |
{ | ||
"name": "mock-js-server", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Mock server for API", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -32,6 +32,2 @@ | ||
app.all('/', (_, res) => | ||
utils.fillResponse(res, | ||
finder.getInfo(config))); | ||
app.all('/**', (req, res, next) => | ||
@@ -38,0 +34,0 @@ next(utils.fillResponse(res, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31205
351