Skip to content

Instantly share code, notes, and snippets.

@hcl1687
Created July 14, 2016 00:59
Show Gist options
  • Save hcl1687/f9f3fca9cbab38f0c146b9fa6c23d2dd to your computer and use it in GitHub Desktop.
Save hcl1687/f9f3fca9cbab38f0c146b9fa6c23d2dd to your computer and use it in GitHub Desktop.
handle dispatcher in nd project
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