forked from Postleaf/postleaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (41 loc) · 1.16 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
// Environment
require('dotenv').config();
process.env.TZ = 'UTC';
// Node modules
const Chalk = require('chalk');
const Express = require('express');
const Fs = require('fs');
const Path = require('path');
const Promise = require('bluebird');
// Local modules
const Postleaf = require(Path.join(__dirname, 'index.js'));
// Express app
const app = Express();
// Configuration options
const options = {
databasePath: Path.join(__dirname, 'data/database.sq3'),
themePath: Path.join(__dirname, 'themes'),
uploadPath: Path.join(__dirname, 'uploads')
};
Promise.resolve()
// Make sure .env exists
.then(() => {
if(!Fs.existsSync(Path.join(__dirname, '.env'))) {
throw new Error('Required config file .env is missing.');
}
})
// Initialize Postleaf
.then(() => Postleaf(app, options))
.then(() => {
// Start sailing! ⚓️
app.listen(process.env.APP_PORT, process.env.APP_HOST || '::', () => {
console.info('Postleaf publishing on port %d! 🌱', process.env.APP_PORT);
});
})
.catch((err) => {
console.error(
Chalk.red('Error: ') + 'Postleaf failed to start! 🐛\n\n' +
Chalk.red(err.stack)
);
});