salix/print/index.js

54 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-09-16 21:13:37 +00:00
const express = require('express');
const path = require('path');
const fs = require('fs');
const templatesPath = path.resolve(__dirname, './templates');
const componentsPath = path.resolve(__dirname, './core/components');
module.exports = {
async boot(app) {
// Init database instance
const conn = app.dataSources.vn.connector.client;
conn.query('SELECT 1', function(error, rows) {
if (error) return error;
console.log(rows);
});
// console.log(app.dataSource.vn.connector.executeStmt('SELECT 1'));
require('./core/database').init(conn);
require('./core/smtp').init();
require('./core/mixins');
require('./core/filters');
require('./core/directives');
const componentsDir = fs.readdirSync(componentsPath);
componentsDir.forEach(componentName => {
const componentDir = path.join(componentsPath, '/', componentName);
const assetsDir = `${componentDir}/assets`;
app.use(`/api/${componentName}/assets`, express.static(assetsDir));
});
/**
* Serve static files
*/
const templatesDir = fs.readdirSync(templatesPath);
templatesDir.forEach(directory => {
const templateTypeDir = path.join(templatesPath, '/', directory);
const templates = fs.readdirSync(templateTypeDir);
templates.forEach(templateName => {
const templateDir = path.join(templatesPath, '/', directory, '/', templateName);
const assetsDir = `${templateDir}/assets`;
app.use(`/api/${templateName}/assets`, express.static(assetsDir));
});
});
return true;
},
smtp: require('./core/smtp'),
db: require('./core/database'),
Email: require('./core/email'),
Report: require('./core/report')
};