-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (59 loc) · 1.6 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
// index.js
/**
* Required External Modules
*/
const os = require('os');
const nr = require('newrelic');
const path = require('path');
const express = require('express');
const winston = require('winston');
const newrelicFormatter = require('@newrelic/winston-enricher');
/**
* App Variables
*/
const app = express();
const port = 4000;
var counter = 0;
const logConfiguration = {
'transports': [
new winston.transports.Console()
],
format: winston.format.combine(
winston.format.label({myTestLabel: 'test123'}),
newrelicFormatter()
)
};
const logger = winston.createLogger(logConfiguration);
/**
* App Configuration
*/
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");
app.use(express.static(path.join(__dirname, "public")));
/**
* Routes Definitions
*/
function between(min, max) {
return Math.floor(
Math.random() * (max - min) + min
)
}
// Set up home route
app.get('/', (req, res) => {
var random_num = between(10,100).toString();
var message = "Thanks for visiting Kubernoodles. Your random number is " + random_num;
res.render("index", { title: "Kubernoodles Demo", test: random_num, hostname: os.hostname() });
logger.info(message);
});
// Set up second page
app.get('/second', (req, res) => {
message = "You've visited the second page. Your random number is " + between(10,100).toString()
res.send(message);
logger.info(message);
});
/**
* Server Activation
*/
app.listen(port, () => {
logger.info(`Success! Your app is running on on port ${port}.`);
});