This repository has been archived by the owner on Dec 3, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
45 lines (38 loc) · 1.61 KB
/
main.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
'use strict'
var _ = require('lodash')
var Promise = require('bluebird')
Promise.longStackTraces()
Promise.promisifyAll(require('fs'))
var config = require('./config')
var bunyan = require('bunyan')
var logging = bunyan.createLogger({name: config.get('app')})
var redis = require('redis')
Promise.promisifyAll(redis.RedisClient.prototype)
Promise.promisifyAll(redis.Multi.prototype)
var redisClient = redis.createClient({host: config.get('redis_host'), port: config.get('redis_port')})
redisClient.on('error', function (err) {
logging.error(err)
})
var Repository = require('./repository')
var SmtpCredentialRepository = new Repository(redisClient, config.get('app') + ':smtp_credentials')
function logItems (info, itemList) {
logging.info(info)
_.map(itemList, function (item) {
logging.info(item[0] + ':', item[1])
})
}
SmtpCredentialRepository.list().then(logItems.bind(null, 'Configured SMTP-Credentials:'))
var TemplateRepository = new Repository(redisClient, config.get('app') + ':templates')
TemplateRepository.list().then(logItems.bind(null, 'Configured Templates:'))
// Set up app
var express = require('express')
var app = express()
require('./api')(app, config, logging, SmtpCredentialRepository, TemplateRepository)
// Expose app
app.listen(config.get('port'), config.get('host'))
logging.info(config.get('app') + ' v' + config.get('version') + ' (Node ' + process.version + ') started')
logging.info('--port ' + config.get('port'))
logging.info('--host ' + config.get('host'))
logging.info('--redis_port ' + config.get('redis_port'))
logging.info('--redis_host ' + config.get('redis_host'))
module.exports = app