Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mock-js-server

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-js-server - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

2

config/routes.json
{
"^$": "../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,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc