35 lines
846 B
JavaScript
35 lines
846 B
JavaScript
|
/* eslint-disable no-console */
|
||
|
const app = require('vn-loopback/server/server');
|
||
|
let dataSources = require('../loopback/server/datasources.json');
|
||
|
|
||
|
async function init() {
|
||
|
console.log('Initializing backend.');
|
||
|
|
||
|
dataSources = JSON.parse(JSON.stringify(dataSources));
|
||
|
Object.assign(dataSources.vn, {
|
||
|
host: process.env.DB_HOST,
|
||
|
port: process.env.DB_PORT
|
||
|
});
|
||
|
|
||
|
const bootOptions = {dataSources};
|
||
|
await new Promise((resolve, reject) => {
|
||
|
app.boot(bootOptions,
|
||
|
err => err ? reject(err) : resolve());
|
||
|
});
|
||
|
// FIXME: Workaround to wait for loopback to be ready
|
||
|
await app.models.Application.status();
|
||
|
}
|
||
|
|
||
|
async function deinit() {
|
||
|
console.log('Stopping backend.');
|
||
|
await app.disconnect();
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
init,
|
||
|
deinit
|
||
|
};
|
||
|
|
||
|
if (require.main === module)
|
||
|
init();
|