mock-responses
Advanced tools
Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "mock-responses", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "espress-kind http request middleware", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -71,5 +71,11 @@ 'use strict;' | ||
function activateByName(key) { | ||
let activateSql = `UPDATE mock_responses SET active = '1' WHERE name like '${key}'`; | ||
const deactivateSql = `UPDATE mock_responses SET active = 0 WHERE name <> '' AND name NOT LIKE '${key}'`; | ||
return db.exec(activateSql) && db.exec(deactivateSql); | ||
} | ||
function getMockResponses(key) { | ||
let sql = `SELECT * FROM mock_responses`; | ||
if (key !== 'undefined') { | ||
if (key !== 'undefined' && key.indexOf('*') === -1) { | ||
sql += ` WHERE name like '%${key}%' OR req_url like '%${key}%' OR res_body like '%${key}%' `; | ||
@@ -192,6 +198,5 @@ } | ||
const reqUrl = url.parse(req.url, true); | ||
if (reqUrl.pathname.match(/^\/developer/)) { | ||
console.log('[mock-resonses]', reqUrl.pathname); | ||
console.log('[mock-responses]', reqUrl.pathname); | ||
const id = (reqUrl.pathname.match(/\/([0-9]+)\/?/) || [])[1]; | ||
@@ -253,3 +258,3 @@ let html; | ||
if (cookies['mock-responses'] === undefined) { | ||
html = 'Unauthorized login'; | ||
html = getHTML('unauthorized.ejs.html'); | ||
} else if (reqUrl.pathname === '/developer/mock-responses.html') { | ||
@@ -275,2 +280,10 @@ data = getMockResponses(reqUrl.query.q); | ||
html = getHTML('index.html'); | ||
} else if (reqUrl.pathname.match(/^\/developer\/[0-9a-zA-Z]+\/batch.html/)) { | ||
let sql = `SELECT DISTINCT name FROM mock_responses`; | ||
data = db.prepare(sql).all(); | ||
html = getHTML('batch.ejs.html', {data}); | ||
} else if (reqUrl.pathname.match(/^\/developer\/activate/)) { | ||
const name = (reqUrl.pathname.match(/^\/developer\/activate\/([0-9a-zA-Z\-]+)/) || [])[1]; | ||
activateByName(name); | ||
html = 'successfully activated'; | ||
} else { | ||
@@ -277,0 +290,0 @@ html = '404 Not Found'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
480320
24
452