2019-10-31 11:43:04 +00:00
|
|
|
const express = require('express');
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
2020-09-14 07:38:48 +00:00
|
|
|
const puppeteer = require('puppeteer');
|
2019-10-31 11:43:04 +00:00
|
|
|
|
|
|
|
const templatesPath = path.resolve(__dirname, './templates');
|
|
|
|
const componentsPath = path.resolve(__dirname, './core/components');
|
2020-09-14 07:38:48 +00:00
|
|
|
const config = require('./core/config');
|
2019-10-31 11:43:04 +00:00
|
|
|
|
2020-09-14 07:38:48 +00:00
|
|
|
module.exports = async app => {
|
2019-10-31 11:43:04 +00:00
|
|
|
global.appPath = __dirname;
|
|
|
|
|
|
|
|
process.env.OPENSSL_CONF = '/etc/ssl/';
|
|
|
|
|
|
|
|
// Extended locale intl polyfill
|
|
|
|
const IntlPolyfill = require('intl');
|
|
|
|
Intl.NumberFormat = IntlPolyfill.NumberFormat;
|
|
|
|
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
|
|
|
|
|
|
|
|
// Init database instance
|
|
|
|
require('./core/database').init();
|
|
|
|
// Init SMTP Instance
|
|
|
|
require('./core/smtp').init();
|
|
|
|
require('./core/mixins');
|
|
|
|
require('./core/filters');
|
|
|
|
require('./core/directives');
|
|
|
|
// Init router
|
|
|
|
require('./core/router')(app);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Serve component static files
|
|
|
|
*/
|
|
|
|
const componentsDir = fs.readdirSync(componentsPath);
|
|
|
|
componentsDir.forEach(componentName => {
|
|
|
|
const componentDir = path.join(componentsPath, '/', componentName);
|
|
|
|
const assetsDir = `${componentDir}/assets`;
|
|
|
|
|
2019-11-07 10:19:05 +00:00
|
|
|
app.use(`/api/${componentName}/assets`, express.static(assetsDir));
|
2019-10-31 11:43:04 +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`;
|
|
|
|
|
2019-11-07 10:19:05 +00:00
|
|
|
app.use(`/api/${templateName}/assets`, express.static(assetsDir));
|
2019-10-31 11:43:04 +00:00
|
|
|
});
|
|
|
|
});
|
2020-09-14 07:38:48 +00:00
|
|
|
|
|
|
|
// Instantiate Puppeteer browser
|
|
|
|
async function launchBrowser() {
|
|
|
|
config.browser = await puppeteer.launch({
|
|
|
|
headless: true,
|
|
|
|
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
|
|
});
|
|
|
|
|
|
|
|
config.browser.on('disconnected', launchBrowser);
|
|
|
|
}
|
|
|
|
|
|
|
|
launchBrowser();
|
2019-10-31 11:43:04 +00:00
|
|
|
};
|