我已经为 hello.js 实现了一个新模块。我需要auth
,grant
并且base
是动态的。有没有办法从hello.init()
调用中设置/覆盖这些值?
我的模块如下所示:
(function(hello) {
hello.init({
my_service_name: {
name: 'My-Service-Name',
oauth: {
version: 2,
auth: 'http://mydomain/oauth/authorize',
grant: 'http://mydomain/oauth/token'
},
scope: {
basic: ['basic_scope']
},
base: 'http://mydomain/',
xhr: function(p) {
if (p.method !== 'get' && p.data) {
// Serialize payload as JSON
p.headers = p.headers || {};
p.headers['Content-Type'] = 'application/json';
if (typeof (p.data) === 'object') {
p.data = JSON.stringify(p.data);
}
}
return true;
}
}
});
})(hello);
我的hello.init()
电话:
hello.init({
my_service_name: server.consumerKey
}, {
redirect_uri : server.callbackUrl,
});
用例是我正在开发的应用程序将与多个服务器通信,因此我无法对模块文件中的 URL 进行硬编码。