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

dmock-server

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dmock-server - npm Package Compare versions

Comparing version 1.2.9 to 1.3.0

22

lib/index.d.ts

@@ -22,3 +22,3 @@ /// <reference types="node" />

*/
constructor(parameters: MockServerParameters);
constructor(parameters: ServerParameters);
/**

@@ -29,16 +29,8 @@ * Starting the mock server

/**
* Setting the headers of the response
* @param res The response object
* @param headers The headers list
*/
setHeaders(res: any, headers: {
[key: string]: any;
} | undefined): void;
/**
* Handling the response
* @param req The request object
* @param res The response object
* @param request The request object
* @param response The response object
* @param route The route object
*/
private handleRequest;
private handleResponse;
/**

@@ -59,3 +51,3 @@ * Stopping the mock server

*/
declare type MockServerParameters = {
declare type ServerParameters = {
hostname?: string;

@@ -82,3 +74,3 @@ port?: number;

[key: string]: any;
} | GenericFunction;
} | ResponseFunction;
};

@@ -92,3 +84,3 @@ /**

*/
declare type GenericFunction = (request: express.Request, response: express.Response) => void;
declare type ResponseFunction = (request: express.Request, response: express.Response) => void;
export {};

@@ -40,17 +40,16 @@ "use strict";

for (const route of this.routes) {
const scope = this;
if (route.method === 'get')
this.handler.get(route.path, function (req, res) { scope.setHeaders(res, route.headers); scope.handleRequest(req, res, route); });
this.handler.get(route.path, (req, res) => this.handleResponse(req, res, route));
else if (route.method === 'post')
this.handler.post(route.path, function (req, res) { scope.setHeaders(res, route.headers); scope.handleRequest(req, res, route); });
this.handler.post(route.path, (req, res) => this.handleResponse(req, res, route));
else if (route.method === 'put')
this.handler.put(route.path, function (req, res) { scope.setHeaders(res, route.headers); scope.handleRequest(req, res, route); });
this.handler.put(route.path, (req, res) => this.handleResponse(req, res, route));
else if (route.method === 'delete')
this.handler.delete(route.path, function (req, res) { scope.setHeaders(res, route.headers); scope.handleRequest(req, res, route); });
this.handler.delete(route.path, (req, res) => this.handleResponse(req, res, route));
else if (route.method === 'patch')
this.handler.patch(route.path, function (req, res) { scope.setHeaders(res, route.headers); scope.handleRequest(req, res, route); });
this.handler.patch(route.path, (req, res) => this.handleResponse(req, res, route));
else if (route.method === 'options')
this.handler.options(route.path, function (req, res) { scope.setHeaders(res, route.headers); scope.handleRequest(req, res, route); });
this.handler.options(route.path, (req, res) => this.handleResponse(req, res, route));
else if (route.method === 'head')
this.handler.head(route.path, function (req, res) { scope.setHeaders(res, route.headers); scope.handleRequest(req, res, route); });
this.handler.head(route.path, (req, res) => this.handleResponse(req, res, route));
}

@@ -60,19 +59,12 @@ this.server = http_1.createServer(this.handler).listen(this.port, this.hostname);

/**
* Setting the headers of the response
* @param res The response object
* @param headers The headers list
*/
setHeaders(res, headers) {
for (const header in headers)
res.set(header, headers[header]);
}
/**
* Handling the response
* @param req The request object
* @param res The response object
* @param request The request object
* @param response The response object
* @param route The route object
*/
handleRequest(req, res, route) {
const response = (typeof route.response === 'function') ? route.response(req, res) : route.response;
res.status((route.statusCode !== undefined) ? route.statusCode : 200).send(response);
handleResponse(request, response, route) {
for (const header in route.headers)
response.set(header, route.headers[header]);
response.status((route.statusCode !== undefined) ? route.statusCode : 200);
response.send((typeof route.response === 'function') ? route.response(request, response) : route.response);
}

@@ -89,6 +81,4 @@ /**

*/
getServer() {
return this.server;
}
getServer() { return this.server; }
}
exports.MockServer = MockServer;
{
"name": "dmock-server",
"version": "1.2.9",
"version": "1.3.0",
"description": "This NodeJS module is a delightful mock server built for automation and ongoing development",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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