mock-responses
Advanced tools
Comparing version 1.1.10 to 1.2.0
{ | ||
"name": "mock-responses", | ||
"version": "1.1.10", | ||
"version": "1.2.0", | ||
"description": "espress-kind http request middleware", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,3 +9,2 @@ 'use strict;' | ||
// -------------------------- Migration start ----------------------- | ||
@@ -34,2 +33,25 @@ // . add res_delay_sec column | ||
// Parse a cookie header | ||
function parseCookies(str) { | ||
var obj = {}; | ||
var pairs = str.split(/; */); | ||
for (var i = 0; i < pairs.length; i++) { | ||
var pair = pairs[i]; | ||
var eq_idx = pair.indexOf('='); | ||
// skip things that don't look like key=value | ||
if (eq_idx < 0) { | ||
continue; | ||
} else { | ||
var key = pair.substr(0, eq_idx).trim() | ||
var val = pair.substr(++eq_idx, pair.length).trim(); | ||
('"' == val[0]) && (val = val.slice(1, -1)); | ||
obj[key] = val; | ||
} | ||
} | ||
return obj; | ||
} | ||
function getHTML(templatePath, data) { | ||
@@ -56,3 +78,3 @@ const contents = fs.readFileSync(path.join(__dirname, 'admin-ui', templatePath), 'utf8'); | ||
} | ||
sql += ' ORDER BY updated_at DESC'; | ||
sql += ' ORDER BY req_url, updated_at DESC'; | ||
return db.prepare(sql).all(); | ||
@@ -230,4 +252,6 @@ } | ||
let sql, ejsPath, data; | ||
if (reqUrl.pathname === '/developer/mock-responses.html') { | ||
const cookies = parseCookies(req.headers.cookie); | ||
if (cookies['mock-responses'] === undefined) { | ||
html = 'Unauthorized login'; | ||
} else if (reqUrl.pathname === '/developer/mock-responses.html') { | ||
data = getMockResponses(reqUrl.query.q); | ||
@@ -234,0 +258,0 @@ html = getHTML('mock-responses.ejs.html', {data}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
478033
439