This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathjsonp.js
49 lines (45 loc) · 1.59 KB
/
jsonp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright 2012-2016 the original author or authors
* @license MIT, see LICENSE.txt for details
*
* @author Scott Andrews
*/
'use strict';
var interceptor, jsonpClient;
interceptor = require('../interceptor');
jsonpClient = require('../client/jsonp');
/**
* Allows common configuration of JSONP clients.
*
* Values provided to this interceptor are added to the request, if the
* request dose not already contain the property.
*
* The rest/client/jsonp client is used by default instead of the
* common default client for the platform.
*
* @param {Client} [client=rest/client/jsonp] custom client to wrap
* @param {string} [config.callback.param] the parameter name for which the
* callback function name is the value
* @param {string} [config.callback.prefix] prefix for the callback function,
* as the callback is attached to the window object, a unique, unobtrusive
* prefix is desired
* @param {string} [request.callback.name=<generated>] pins the name of the
* callback function, useful for cases where the server doesn't allow
* custom callback names. Generally not recommended.
*
* @returns {Client}
*/
module.exports = interceptor({
client: jsonpClient,
init: function (config) {
config.callback = config.callback || {};
return config;
},
request: function (request, config) {
request.callback = request.callback || {};
request.callback.param = request.callback.param || config.callback.param;
request.callback.prefix = request.callback.prefix || config.callback.prefix;
request.callback.name = request.callback.name || config.callback.name;
return request;
}
});