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

@ashvajs/mock-server

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ashvajs/mock-server - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

LICENCE

2

package.json
{
"name": "@ashvajs/mock-server",
"version": "0.0.6",
"version": "0.0.7",
"dependencies": {

@@ -5,0 +5,0 @@ "fs": "^0.0.1-security",

@@ -14,18 +14,21 @@ # @ashvajs/mock-server

## Folder structure
```
mocks
api
v1
test
post.json // serves as /api/v1/test [post method]
get.json // serves as /api/v1/test [get method]
delete.json // serves as /api/v1/test [delete method]
patch.json // serves as /api/v1/test [patch method]
dynamic // for dynamic routes
post
index.js
get
index.js
..api
....v1
......test // route
........post.json // serves as /api/v1/test [post method]
........get.json // serves as /api/v1/test [get method]
........delete.json // serves as /api/v1/test [delete method]
........patch.json // serves as /api/v1/test [patch method]
......dynamic // route
........post // for dynamic routes
..........index.js
........get
..........index.js
```
## Example
```

@@ -32,0 +35,0 @@ import path from 'path';

@@ -6,5 +6,5 @@ declare class MockServer {

constructor({ fse, ...options }: any, app: any);
ensureSlash(path: any): any;
ensureNoSlash(path: any): any;
init(): void;
}
export { MockServer };

@@ -6,2 +6,3 @@ "use strict";

const fs = require("fs");
const path = require("path");
const response_1 = require("./response");

@@ -16,4 +17,6 @@ const error_1 = require("./error");

}
ensureSlash(path) {
return path.substr(path.length - 1, 1) === '/' ? path : `${path}/`;
ensureNoSlash(path) {
return path.substr(path.length - 1, 1) === '/'
? path.substr(0, path.length - 1)
: `${path}`;
}

@@ -23,16 +26,17 @@ init() {

this.app.all(this.config.staticMocks, (req, res) => {
const path = req._parsedUrl.pathname;
const reqPath = req._parsedUrl.pathname;
const method = req.method.toLowerCase();
let finalPath = this.ensureSlash(this.config.staticApiPath) + path;
let finalPath = reqPath.resolve(this.ensureNoSlash(this.config.staticApiPath), reqPath);
// console.log(finalPath);
let response = new response_1.default(error_1.default.notfound()).error();
let isJs = false;
if (this.fse.existsSync(`${finalPath}/${method}/index.js`)) {
finalPath = `${finalPath}/${method}/index.js`;
if (this.fse.existsSync(path.join(finalPath, method, 'index.js'))) {
finalPath = path.join(finalPath, method, 'index.js');
isJs = true;
}
else if (this.fse.existsSync(`${finalPath}/${method}.json`)) {
finalPath = `${finalPath}/${method}.json`;
else if (this.fse.existsSync(path.join(finalPath, `${method}.json`))) {
finalPath = path.join(finalPath, `${method}.json`);
}
else if (this.fse.existsSync(`${finalPath}/index.json`)) {
finalPath = `${finalPath}/index.json`;
else if (this.fse.existsSync(path.join(finalPath, `index.json`))) {
finalPath = path.join(finalPath, `index.json`);
}

@@ -39,0 +43,0 @@ console.log(`mock serving_path=${finalPath}`);

Sorry, the diff of this file is not supported yet

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