From e925015d10e554534b64f8b9fc16588a4c90fde1 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Sat, 12 Aug 2017 19:36:43 +0800 Subject: [web] Update fetch api to suite the static mode. --- web/src/js/utils.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'web/src/js/utils.js') diff --git a/web/src/js/utils.js b/web/src/js/utils.js index e8470cec..68daa1ad 100644 --- a/web/src/js/utils.js +++ b/web/src/js/utils.js @@ -81,7 +81,21 @@ function getCookie(name) { } const xsrf = `_xsrf=${getCookie("_xsrf")}`; + export function fetchApi(url, options={}) { + if (global.MITMWEB_STATIC) { + let path = url.split('/'), + filename = path.pop() + filename = '_' + filename + path.push(filename) + let new_url = path.join('/') + return _fetchApi(new_url, options) + } else { + return _fetchApi(url, options) + } +} + +function _fetchApi(url, options={}) { if (options.method && options.method !== "GET") { if (url.indexOf("?") === -1) { url += "?" + xsrf; @@ -96,7 +110,7 @@ export function fetchApi(url, options={}) { }); } -fetchApi.put = (url, json, options) => fetchApi( +fetchApi.put = (url, json, options) => _fetchApi( url, { method: "PUT", -- cgit v1.2.3 From cbdddefcc8f3ad19e50da5a31532c8abb0cb36f8 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Mon, 14 Aug 2017 10:11:48 +0800 Subject: [web] change the path name like `_flows` to `flows.json`. --- web/src/js/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/src/js/utils.js') diff --git a/web/src/js/utils.js b/web/src/js/utils.js index 68daa1ad..505f74df 100644 --- a/web/src/js/utils.js +++ b/web/src/js/utils.js @@ -86,7 +86,7 @@ export function fetchApi(url, options={}) { if (global.MITMWEB_STATIC) { let path = url.split('/'), filename = path.pop() - filename = '_' + filename + filename += '.json' path.push(filename) let new_url = path.join('/') return _fetchApi(new_url, options) -- cgit v1.2.3 From 6560b0dcdba72085ce6c53d68a9e01d293936893 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 15 Aug 2017 22:21:08 +0800 Subject: [web] Change the api routing and minor fix. --- web/src/js/utils.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'web/src/js/utils.js') diff --git a/web/src/js/utils.js b/web/src/js/utils.js index 505f74df..3aeba1b1 100644 --- a/web/src/js/utils.js +++ b/web/src/js/utils.js @@ -81,27 +81,15 @@ function getCookie(name) { } const xsrf = `_xsrf=${getCookie("_xsrf")}`; - export function fetchApi(url, options={}) { - if (global.MITMWEB_STATIC) { - let path = url.split('/'), - filename = path.pop() - filename += '.json' - path.push(filename) - let new_url = path.join('/') - return _fetchApi(new_url, options) - } else { - return _fetchApi(url, options) - } -} - -function _fetchApi(url, options={}) { if (options.method && options.method !== "GET") { if (url.indexOf("?") === -1) { url += "?" + xsrf; } else { url += "&" + xsrf; } + } else { + url += '.json' } return fetch(url, { @@ -110,7 +98,7 @@ function _fetchApi(url, options={}) { }); } -fetchApi.put = (url, json, options) => _fetchApi( +fetchApi.put = (url, json, options) => fetchApi( url, { method: "PUT", -- cgit v1.2.3