2016-09-15 17:16:42 +00:00
|
|
|
|
{"version":3,"file":null,"sources":["lib/methods.js","lib/requester.js","lib/settings.js","lib/middleware.js","lib/router.js","lib/application.js","lib/frontexpress.js"],"sourcesContent":["/**\n * HTTP method list\n * @private\n */\n\n export default ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH'];","/**\n * Module dependencies.\n * @private\n */\n\nexport default class Requester {\n\n /**\n * Make an ajax request.\n *\n * @param {Object} request\n * @param {Function} success callback\n * @param {Function} failure callback\n * @private\n */\n\n fetch(request, resolve, reject) {\n const {method, uri, headers, data} = request;\n\n const success = (responseText) => {\n resolve(\n request,\n {status: 200, statusText: 'OK', responseText}\n );\n };\n\n const fail = ({status, statusText, errorThrown}) => {\n const errors = this._analyzeErrors({status, statusText, errorThrown});\n reject(\n request,\n {status, statusText, errorThrown, errors}\n );\n };\n\n const xmlhttp = new XMLHttpRequest();\n xmlhttp.onreadystatechange = () => {\n if (xmlhttp.readyState === 4) {\n if (xmlhttp.status === 200) {\n success(xmlhttp.responseText);\n } else {\n fail({status: xmlhttp.status, statusText: xmlhttp.statusText});\n }\n }\n };\n try {\n xmlhttp.open(method, uri, true);\n if (headers) {\n for (const header of Object.keys(headers)) {\n xmlhttp.setRequestHeader(header, headers[header]);\n }\n }\n if (data) {\n xmlhttp.send(data);\n } else {\n xmlhttp.send();\n }\n } catch (errorThrown) {\n fail({errorThrown});\n }\n }\n\n\n /**\n * Analyse response errors.\n *\n * @private\n */\n\n _analyzeErrors(response) {\n // manage exceptions\n if (response.errorThrown) {\n if (response.errorThrown.name === 'SyntaxError') {\n return 'Problem during data decoding [JSON]';\n }\n if (response.errorThrown.name === 'TimeoutError') {\n return 'Server is taking too long to reply';\n }\n if (response.errorThrown.name === 'AbortError') {\n return 'Request cancelled on server';\n }\n if (response.errorThrown.name === 'NetworkError') {\n return 'A network error occurred';\n }\n throw response.errorThrown;\n }\n\n // manage status\n if (response.status === 0) {\n return 'Server access problem. Check your network connection';\n }\n if (response.status === 401) {\n return 'Your session has expired, Please reconnect. [code: 401]';\n }\n if (response.status === 404) {\n return 'Page not found on server. [code: 404]';\n }\n if (response.status === 500) {\n return 'Internal server error. [code: 500]';\n }\n return `Unknown error. ${response.statusText?response.statusText:''}`;\n }\n}","/**\n * Module dependencies.\n * @private\n */\n\nimport Requester from './requester';\n\n\n/**\n * Settings object.\n * @private\n */\n\nexport default class Settings {\n\n\n /**\n * Initialize the settings.\n *\n * - setup default configuration\n *\n * @private\n */\n\n constructor() {\n // default settings\n this.settings = {\n 'http requester': new Requester(),\n\n 'http GET transformer': {\n uri({uri, headers, data}) {\n if (!data) {\n return uri;\n }\n\n let anchor = '';\n let
|