Merge pull request #77 from agriwebb/pass-args-connector
Add support for configuring remoting options
This commit is contained in:
commit
607fec76be
|
@ -29,14 +29,14 @@ module.exports = RemoteConnector;
|
|||
function RemoteConnector(settings) {
|
||||
assert(typeof settings ===
|
||||
'object',
|
||||
'cannot initiaze RemoteConnector without a settings object');
|
||||
'cannot initialize RemoteConnector without a settings object');
|
||||
this.client = settings.client;
|
||||
this.adapter = settings.adapter || 'rest';
|
||||
this.protocol = settings.protocol || 'http';
|
||||
this.root = settings.root || '';
|
||||
this.host = settings.host || 'localhost';
|
||||
this.port = settings.port || 3000;
|
||||
this.remotes = remoting.create();
|
||||
this.remotes = remoting.create(settings.options);
|
||||
this.name = 'remote-connector';
|
||||
|
||||
if (settings.url) {
|
||||
|
|
|
@ -12,6 +12,7 @@ var remoteConnector = require('..');
|
|||
exports.createMemoryDataSource = createMemoryDataSource;
|
||||
exports.createModel = createModel;
|
||||
exports.createRemoteDataSource = createRemoteDataSource;
|
||||
exports.createRemoteDataSourceWithOptions = createRemoteDataSourceWithOptions;
|
||||
exports.createRestAppAndListen = createRestAppAndListen;
|
||||
exports.getUserProperties = getUserProperties;
|
||||
|
||||
|
@ -44,6 +45,14 @@ function createRemoteDataSource(remoteApp) {
|
|||
});
|
||||
}
|
||||
|
||||
function createRemoteDataSourceWithOptions(remoteApp, options) {
|
||||
return loopback.createDataSource({
|
||||
url: 'http://anyURL.com',
|
||||
connector: remoteConnector,
|
||||
options: options
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to create models based on a set of options. May associate or link to an
|
||||
* app.
|
||||
|
|
|
@ -134,3 +134,15 @@ describe('Custom Path', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('RemoteConnector with options', () => {
|
||||
it('should have the remoting options passed to the remote object', () => {
|
||||
const serverApp = helper.createRestAppAndListen();
|
||||
|
||||
const datasource = helper.createRemoteDataSourceWithOptions(
|
||||
serverApp,
|
||||
{'test': 'abc'});
|
||||
|
||||
assert.deepEqual(datasource.connector.remotes.options, {test: 'abc'});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue