homepage.js/startup.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-02-13 02:16:46 +01:00
console.log('Executing startup jobs...');
const fs = require('fs');
2023-03-19 10:10:05 +01:00
const { crc32 } = require('easy-crc');
2023-02-25 07:32:11 +01:00
const glob = require('glob');
const { exec } = require('child_process');
2023-02-13 02:16:46 +01:00
const hrt = () => {
let hr = process.hrtime();
return hr[0] + hr[1] / 1000000;
}
2023-02-18 16:29:32 +01:00
// load dotenv
let dotpath = (process.env.APP_DEBUG == 'true') ? '.env.debug' : '.env.prod';
if (!fs.existsSync(dotpath)) dotpath = '.env';
require('dotenv').config({
path: dotpath
});
2023-02-19 03:32:08 +01:00
// load debug
2023-03-05 15:26:56 +01:00
if (process.env.APP_DEBUG == 'true') {
process.env.APP_DEBUG = true;
2023-02-19 03:32:08 +01:00
process.env.DEBUG = '*/*';
2023-03-10 08:39:27 +01:00
} else {
process.env.DEBUG = null;
process.env.NODE_DEBUG = null;
process.env.APP_DEBUG = false;
}
// build resume page
if ((!fs.existsSync('public/static/dist/resume.js')) && (!process.env.APP_DEBUG)) {
console.log('Resume files do not exist, building it automatically...');
exec('react/resume/build.sh');
2023-02-19 03:32:08 +01:00
}
2023-02-18 16:29:32 +01:00
// load key
if (!process.env.APP_KEY)
throw new Error('APP_KEY is not set.')
2023-02-13 02:16:46 +01:00
2023-02-25 07:32:11 +01:00
// import gpg keys
glob('data/userdata/*_gpgkey', async (err, files) => {
if (err) {
console.error(err);
process.exit(-1);
}
files.filter(
file => {
return !file.startsWith('.')
}
).forEach(file => {
exec('gpg --import ' + file, (err, stdout, stderr) => {
if (err) {
console.error(`Errors while importing ${file}: ${err}`);
process.exit(-1);
}
console.log(`Imported ${file} key`);
});
});
});
2023-03-19 10:10:05 +01:00
console.log('Using a key with CRC32: ' + crc32('CRC-32', process.env.APP_KEY));
2023-02-13 02:16:46 +01:00
2023-02-18 16:29:32 +01:00
async function startup() {
let t1 = hrt();
2023-02-18 16:03:27 +01:00
2023-02-13 02:16:46 +01:00
await require('./helpers').ViewLoader.preload();
console.log('Views compiled in ' + (hrt() - t1) + ' ms');
console.log('Finished in ' + (hrt() - t1) + " ms");
}
2023-02-18 16:29:32 +01:00
module.exports = startup();