forked from gordienko/postleaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (44 loc) · 1.4 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
49
50
51
'use strict';
const Fs = require('fs');
// Environment
if (process.env.ENV_FILE_PATH && Fs.existsSync(process.env.ENV_FILE_PATH)) {
require('dotenv').config({ path: process.env.ENV_FILE_PATH });
} else {
// Make sure .env exists
if (!Fs.existsSync(Path.join(__dirname, '.env'))) {
throw new Error('Required config file .env is missing.');
} else {
require('dotenv').config();
}
}
process.env.TZ = 'UTC';
// Node modules
const Chalk = require('chalk');
const Express = require('express');
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: process.env.DATABASE_FILE_PATH || Path.join(__dirname, 'data/database.sq3'),
themePath: process.env.THEMES_DIR_PATH || Path.join(__dirname, 'themes'),
uploadPath: process.env.UPLOADS_DIR_PATH || Path.join(__dirname, 'uploads')
};
Promise.resolve()
// 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)
);
});