-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
34 lines (25 loc) · 855 Bytes
/
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
// Enable promise error logging
require('promise/lib/rejection-tracking').enable();
var express = require('express');
var app = express();
var certificate = require('./src/certificate')
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.get('/', function(request, response) {
certificate.getCertificationData().then(function(data) {
responseData = {
certInfo: JSON.stringify(data),
runDate: new Date().toDateString()
}
if(request.headers['content-type'] == 'application/json') {
response.json(responseData);
} else {
response.render('pages/index', responseData);
}
});
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});