forked from jenkoian/hacktoberfest-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
91 lines (78 loc) · 2.14 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
const express = require('express');
const path = require('path');
const logger = require('morgan');
const compression = require('compression');
const bodyParser = require('body-parser');
const dotenv = require('dotenv');
const exphbs = require('express-handlebars');
const _ = require('lodash');
const q = require('q');
const GitHubApi = require('github');
// Load environment variables from .env file
dotenv.load();
// Controllers
const IndexController = require('./controllers/index');
const app = express();
const hbs = exphbs.create({
defaultLayout: 'main',
helpers: {
ifeq(a, b, options) {
if (a === b) {
return options.fn(this);
}
return options.inverse(this);
},
toJSON(object) {
return JSON.stringify(object);
},
exists(variable, options) {
if (typeof variable !== 'undefined') {
return options.fn(this);
}
},
timeago: require('helper-timeago')
},
extname: 'hbs'
});
const github = new GitHubApi({
version: '3.0.0',
debug: false,
protocol: 'https',
host: 'api.github.com',
timeout: 5000,
headers: {
'user-agent': 'Hacktoberfest Checker'
}
});
if (process.env.GITHUB_TOKEN) {
github.authenticate({
type: 'oauth',
token: process.env.GITHUB_TOKEN
});
} else {
console.log('No GITHUB_TOKEN specified, do so to increase rate limit');
}
app.engine('hbs', hbs.engine);
app.set('view engine', 'hbs');
app.set('port', process.env.PORT || 5000);
app.set('q', q);
app.set('_', _);
app.set('github', github);
app.use(compression());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', IndexController.index);
// Production error handler
if (app.get('env') === 'production') {
app.use((err, req, res) => {
console.error(err.stack);
res.sendStatus(err.status || 500);
});
}
app.listen(app.get('port'), () => {
console.log(`Express server listening on port ${app.get('port')}`);
});
module.exports = app;