2016-05-06 19:02:21 +00:00
|
|
|
// Copyright IBM Corp. 2016. All Rights Reserved.
|
|
|
|
// Node module: loopback-connector-remote
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2016-09-01 08:12:12 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-09-01 09:56:33 +00:00
|
|
|
var extend = require('util')._extend;
|
2016-01-07 06:45:29 +00:00
|
|
|
var loopback = require('loopback');
|
|
|
|
var remoteConnector = require('..');
|
|
|
|
|
|
|
|
exports.createMemoryDataSource = createMemoryDataSource;
|
|
|
|
exports.createRemoteDataSource = createRemoteDataSource;
|
|
|
|
exports.createRestAppAndListen = createRestAppAndListen;
|
|
|
|
exports.getUserProperties = getUserProperties;
|
|
|
|
|
2016-02-05 12:29:43 +00:00
|
|
|
function createRestAppAndListen() {
|
2017-12-11 13:45:43 +00:00
|
|
|
const app = loopback({localRegistry: true});
|
2016-01-07 06:45:29 +00:00
|
|
|
|
|
|
|
app.set('host', '127.0.0.1');
|
2016-02-05 12:29:43 +00:00
|
|
|
app.set('port', 0);
|
2016-01-07 06:45:29 +00:00
|
|
|
|
2016-09-01 08:24:56 +00:00
|
|
|
app.set('legacyExplorer', false);
|
|
|
|
app.set('remoting', {
|
|
|
|
errorHandler: { debug: true, log: false },
|
|
|
|
context: false,
|
|
|
|
});
|
|
|
|
|
2016-01-07 06:45:29 +00:00
|
|
|
app.use(loopback.rest());
|
|
|
|
app.locals.handler = app.listen();
|
|
|
|
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2017-12-11 13:45:43 +00:00
|
|
|
function createMemoryDataSource(app) {
|
|
|
|
return app.dataSource('db', {connector: 'memory'});
|
2016-01-07 06:45:29 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 13:45:43 +00:00
|
|
|
function createRemoteDataSource(app, serverApp) {
|
|
|
|
return app.dataSource('remote', {
|
|
|
|
url: 'http://' + serverApp.get('host') + ':' + serverApp.get('port'),
|
2016-01-07 06:45:29 +00:00
|
|
|
connector: remoteConnector
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUserProperties() {
|
|
|
|
return {
|
|
|
|
'first': String,
|
|
|
|
'last': String,
|
|
|
|
'age': Number,
|
|
|
|
'password': String,
|
|
|
|
'gender': String,
|
|
|
|
'domain': String,
|
|
|
|
'email': String
|
|
|
|
};
|
|
|
|
}
|