@zemke/http-mock
Advanced tools
Comparing version 2.0.4 to 3.0.0
19
index.js
@@ -23,2 +23,4 @@ const http = require('http'); | ||
if (req.method.toUpperCase() === 'OPTIONS') return res.end(); | ||
const matchingMocks = mocks.filter(m => urlMatchesPattern(req.url, m[0])); | ||
@@ -39,6 +41,17 @@ | ||
try { | ||
res.end(JSON.parse(JSON.stringify(mock))); | ||
if (typeof mock === "object") { | ||
console.log(`Serving inline mock for ${req.url}`); | ||
} catch (e) { | ||
res.end(JSON.stringify(mock)); | ||
} else if (typeof mock === "function") { | ||
console.log(`Serving mock from function for ${req.url}`); | ||
if (req.method.toUpperCase() === 'POST') { | ||
let body = ""; | ||
req | ||
.on('data', chunk => body += chunk) | ||
.on('end', () => res.end(JSON.stringify(mock(req, JSON.parse(body.toString()))))); | ||
} else { | ||
res.end(JSON.stringify(mock(req))); | ||
} | ||
} else { | ||
if (!fs.existsSync(mock)) { | ||
@@ -45,0 +58,0 @@ console.warn(`HTTP500 - ${mock} does not exist.`); |
{ | ||
"name": "@zemke/http-mock", | ||
"version": "2.0.4", | ||
"version": "3.0.0", | ||
"description": "Serve JSON mocks conveniently.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
4344
67