salix/print/index.js

54 lines
1.8 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) {
2022-10-25 06:16:56 +00:00
// Extended locale intl polyfill
const IntlPolyfill = require('intl');
Intl.NumberFormat = IntlPolyfill.NumberFormat;
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
2022-09-27 12:20:57 +00:00
2022-10-25 06:16:56 +00:00
// Init database instance
2022-09-27 12:20:57 +00:00
require('./core/database').init(app.dataSources);
2022-09-16 21:13:37 +00:00
require('./core/smtp').init();
2022-10-19 12:30:36 +00:00
require('./core/cluster').init();
2022-09-16 21:13:37 +00:00
require('./core/mixins');
require('./core/filters');
const componentsDir = fs.readdirSync(componentsPath);
componentsDir.forEach(componentName => {
const componentDir = path.join(componentsPath, '/', componentName);
const assetsDir = `${componentDir}/assets`;
2022-09-27 12:20:57 +00:00
2022-09-16 21:13:37 +00:00
app.use(`/api/${componentName}/assets`, express.static(assetsDir));
});
2022-09-27 12:20:57 +00:00
/**
2022-09-16 21:13:37 +00:00
* 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;
},
Email: require('./core/email'),
2022-09-29 05:35:20 +00:00
Report: require('./core/report'),
storage: require('./core/storage'),
smtp: require('./core/smtp'),
db: require('./core/database')
2022-09-16 21:13:37 +00:00
};