-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyApp.js
39 lines (30 loc) · 850 Bytes
/
myApp.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
var express = require('express');
var app = express();
require('dotenv').config();
console.log("Hello World");
app.use('/public', express.static(`${__dirname}/public/`))
app.use(function (req, res, next){
console.log(`${req.method} ${req.path} - ${req.ip}`)
next()
})
function getCurrentTimeString(){
return new Date().toString();
}
app.get('/now', (req, res, next) => {
req.time = getCurrentTimeString();
next();
}, (req, res) => {
res.json({time : req.time})
})
app.get('/', (req, res) => {
res.sendFile(`${__dirname}/views/index.html`);
})
app.get('/json', function(req, res) {
if(process.env.MESSAGE_STYLE === "uppercase"){
res.json({'message': 'HELLO JSON'})
} else {
console.log(process.env.MESSAGE_STYLE);
res.json({'message': 'Hello json'})
}
})
module.exports = app;