Вот мое решение.
domainService.js:
const
ispwrapper = require('../lib/ispwrapper');
require('dotenv').config();
const BASE_URL = process.env.API_BASE_URL;
const OPTIONS = {
username: process.env.API_USERNAME,
password: process.env.API_PASSWORD
};
const getDomains = async () => {
let data = [];
try {
let a = new ispwrapper.ISPConfig(BASE_URL, OPTIONS);
let response = await a.getDataByPrimaryId('sites_web_domain_get', { active: 'y' });
for (let i = 0; i < response.length; i++){
data.push(response[i].domain);
}
return data;
} catch(err) {
console.log(err);
}
};
module.exports = {
getDomains
};
homeController:
const homeService = require('../services/domainService');
const renderHome = async (req, res) => {
let message = '',
domain = [];
try {
let response = await homeService.getDomains();
for (let i = 0; i < response.length; i++){
domain.push(response[i]);
}
} catch(err) {
message = 'Error when retriving domains from API';
} finally {
res.render('home', {
title: 'ISPConfig',
heading: 'Welcome to my ISPConfig Dashboard',
homeActive: true,
domain,
message
});
}
};
module.exports = {
renderHome
};