-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (58 loc) · 1.59 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
52
53
54
55
56
57
58
59
60
61
62
63
64
// Initialize Express
const express = require('express');
const app = express();
app.set('port', (process.env.PORT || 5000));
// Initialize cache
const redis = require('redis');
const redisOptions = {
host: process.env.REDIS_HOST,
db: 1,
port: 6379,
total_retry_time: 300000
};
const client = redis.createClient(redisOptions);
client.on('error', err => logger.error('redis error - ' + err));
client.on('connect', () => {
logger.info('redis connected');
app.listen(app.get('port'), logger.info('Application listening on port', app.get('port')));
});
const Redis = require('./server/classes/Redis');
let r = new Redis(client);
module.exports = {redis: r};
// Initialize logger
const log4js = require('log4js');
log4js.configure({
pm2: true,
appenders: {
out: {
type: 'console',
category: 'purdue-laundry'
},
// Commenting out loggly stuff since it doesn't work and I have no idea what loggly account it goes to
//loggly: {
// type: 'loggly',
// token: '5ac059d3-1b8c-4e5e-9059-0b6b080b3fee',
// subdomain: 'purduesigapp',
// tags: ['purdue-laundry'],
// category: 'purdue-laundry',
// json: true
//},
},
categories: {
default: { appenders: [ 'out' ], level: 'info' },
//loggly: { appenders: ['loggly'], level: 'info'}
}
});
const logger = log4js.getLogger('purdue-laundry');
// Provide caching and logging to controllers
app.use((req, res, next) => {
req.logger = logger;
// req.stats = stats;
next();
});
// Set up routes
require('./server/routes')(app, r);
// Print the ASCII art
const fs = require('fs');
const art = fs.readFileSync('./ascii-art.txt', 'utf-8');
logger.info(art);