Created
July 14, 2016 00:59
-
-
Save hcl1687/f9f3fca9cbab38f0c146b9fa6c23d2dd to your computer and use it in GitHub Desktop.
handle dispatcher in nd project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function handleDispatcher (options) { | |
if (!DISPATCHER_ENABLE) { | |
return | |
} | |
const inIgnore = DISPATCHER_IGNORE.some(res => { | |
return options.url && options.url.indexOf(res) > -1 | |
}) | |
if (inIgnore) { | |
return | |
} | |
const params = options.params | |
let query = options.query | |
const url = options.url | |
const urlObj = parseUrl(url) | |
const dispatcher = Object.assign({}, urlObj) | |
if (query) { | |
if (typeof query === 'object') { | |
query = qs.stringify(query) | |
} | |
dispatcher.api += ((url.indexOf('?') !== -1) ? '&' : '?') + query | |
} | |
dispatcher.api = encodeURIComponent(dispatcher.api) | |
dispatcher.vars = params || {} | |
const vorg = options.headers && options.headers.vorg | |
if (vorg) { | |
dispatcher.header = { | |
vorg | |
} | |
} | |
options.headers = options.headers || {} | |
options.headers.Dispatcher = JSON.stringify(dispatcher) | |
options.url = `${LOC_RES}/dispatcher${urlObj.api}` | |
return options | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment