Socket
Socket
Sign inDemoInstall

@mocks-server/core

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mocks-server/core - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

11

CHANGELOG.md

@@ -17,2 +17,13 @@ # Change Log

## [2.1.0] - 2021-03-23
### Added
- feat: Support array of methods in routes (#139)
- feat: Support OPTIONS, HEAD and TRACE http methods in routes (#140)
- feat: Add cors and corsPreFlight options (#140)
### Changed
- chore(deps): Update dependencies
## [2.0.0] - 2021-01-17

@@ -19,0 +30,0 @@

10

package.json
{
"name": "@mocks-server/core",
"version": "2.0.0",
"version": "2.1.0",
"description": "Pluggable mock server supporting multiple route variants and mocks",

@@ -43,3 +43,3 @@ "keywords": [

"body-parser": "1.19.0",
"@hapi/boom": "9.1.1",
"@hapi/boom": "9.1.2",
"commander": "6.2.1",

@@ -61,5 +61,5 @@ "cors": "2.8.5",

"devDependencies": {
"cross-fetch": "3.0.6",
"cross-fetch": "3.1.2",
"cross-spawn": "7.0.3",
"eslint": "7.20.0",
"eslint": "7.22.0",
"eslint-plugin-no-only-tests": "2.4.0",

@@ -77,3 +77,3 @@ "eslint-config-prettier": "7.2.0",

"tree-kill": "1.2.2",
"wait-on": "5.2.1"
"wait-on": "5.3.0"
},

@@ -80,0 +80,0 @@ "lint-staged": {

@@ -12,3 +12,3 @@ [![Build status][build-image]][build-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Quality Gate][quality-gate-image]][quality-gate-url]

Use it if you want to start the mocks-server programmatically by your own, or even create your own mocks-server distribution with your desired plugins. If not, you would probably prefer using the [main distribution of the Mocks Server project][main-url].
Use it if you want to start Mocks Server programmatically by your own, or even create your own Mocks Server distribution with your desired plugins. If not, you would probably prefer using the [main distribution of the Mocks Server project][main-url].

@@ -15,0 +15,0 @@ ## Documentation

@@ -35,2 +35,8 @@ // For a detailed explanation regarding each configuration property, visit:

// Cors middleware
// cors: true,
// Cors pre-flight
// corsPreFlight: true,
// Legacy path containing mocks in v1 format

@@ -37,0 +43,0 @@ // pathLegacy: "mocks-legacy",

@@ -21,2 +21,5 @@ /*

PUT: "put",
OPTIONS: "options",
HEAD: "head",
TRACE: "trace",
};

@@ -35,17 +38,22 @@

this._routesVariants.forEach((routeVariant) => {
this._router[METHODS[routeVariant.method]](routeVariant.url, (req, res, next) => {
const delay = routeVariant.delay !== null ? routeVariant.delay : this._getDelay();
if (delay > 0) {
tracer.verbose(`Applying delay of ${delay}ms to route variant "${this._id}"`);
setTimeout(() => {
const methods = Array.isArray(routeVariant.method)
? routeVariant.method
: [routeVariant.method];
methods.forEach((method) => {
this._router[METHODS[method]](routeVariant.url, (req, res, next) => {
const delay = routeVariant.delay !== null ? routeVariant.delay : this._getDelay();
if (delay > 0) {
tracer.verbose(`Applying delay of ${delay}ms to route variant "${this._id}"`);
setTimeout(() => {
next();
}, delay);
} else {
next();
}, delay);
} else {
next();
}
}
});
this._router[METHODS[method]](
routeVariant.url,
routeVariant.middleware.bind(routeVariant)
);
});
this._router[METHODS[routeVariant.method]](
routeVariant.url,
routeVariant.middleware.bind(routeVariant)
);
});

@@ -52,0 +60,0 @@ }

@@ -36,5 +36,11 @@ /*

_onChangeSettings(changeDetails) {
if (changeDetails.hasOwnProperty("port") || changeDetails.hasOwnProperty("host")) {
if (
changeDetails.hasOwnProperty("port") ||
changeDetails.hasOwnProperty("host") ||
changeDetails.hasOwnProperty("cors") ||
changeDetails.hasOwnProperty("corsPreFlight")
) {
this._server.restart();
}
// TODO, remove legacy
if (changeDetails.hasOwnProperty("behavior")) {

@@ -41,0 +47,0 @@ this._legacyMocks.behaviors.current = changeDetails.behavior;

@@ -21,4 +21,2 @@ /*

constructor(route, core) {
this._method = route.method;
this._url = route.url;
this._response = route.response;

@@ -25,0 +23,0 @@ this._variantId = route.variantId;

@@ -16,3 +16,3 @@ /*

const Boom = require("@hapi/boom");
const cors = require("cors");
const expressRequestId = require("express-request-id");

@@ -24,3 +24,2 @@

const jsonBodyParser = bodyParser.json();
const enableCors = cors();

@@ -57,5 +56,4 @@ const traceRequest = (req, res, next) => {

traceRequest,
enableCors,
notFound,
errorHandler,
};

@@ -18,2 +18,3 @@ /*

const { delay } = require("lodash");
const cors = require("cors");
const tracer = require("../tracer");

@@ -58,4 +59,9 @@ const middlewares = require("./middlewares");

this._express.use(middlewares.addRequestId);
this._express.use(middlewares.enableCors);
this._express.options("*", middlewares.enableCors);
if (this._settings.get("cors")) {
this._express.use(
cors({
preflightContinue: !this._settings.get("corsPreFlight"),
})
);
}
this._express.use(middlewares.jsonBodyParser);

@@ -62,0 +68,0 @@ this._express.use(middlewares.traceRequest);

@@ -23,3 +23,3 @@ /*

this._optionsNames = Object.keys(defaultOptions);
this._booleanOptionsWithTrueDefaults = [];
this._booleanOptionsWithTrueDefaults = ["cors", "corsPreFlight"];
// TODO, generate initial options dynamically from Options object using the "addCustom" method

@@ -33,3 +33,5 @@ this._commander = commander

.option("--log <log>", "Log level")
.option("--port <port>", "Port for server", parseInt);
.option("--port <port>", "Port for server", parseInt)
.option("--no-cors", "Disable cors middleware")
.option("--no-corsPreFlight", "Disable cors pre-flight middleware");
}

@@ -36,0 +38,0 @@

@@ -24,2 +24,4 @@ /*

log: "info",
cors: true,
corsPreFlight: true,
// TODO, remove v1 legacy code

@@ -26,0 +28,0 @@ behavior: null,

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