-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
37 lines (30 loc) · 846 Bytes
/
main.js
File metadata and controls
37 lines (30 loc) · 846 Bytes
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
const { join } = require('path')
const express = require('express')
const hbs = require('express-handlebars')
const PORT = parseInt(process.argv[2]) || parseInt(process.env.APP_PORT) || 3000
const app = express()
app.engine('hbs', hbs({ defaultLayout: false }))
app.set('view engine', 'hbs')
app.get('/time', (req, resp) => {
const t = (new Date()).toString()
console.log(req.get('accept'))
resp.status(200)
resp.format({
'text/html': () => {
resp.type('text/html')
resp.render('time', { time: t })
},
'application/json': () => {
resp.json({ time: t })
},
'default': () => {
resp.type('text/html')
resp.render('time', { time: t })
}
})
})
app.use(express.static(join(__dirname, 'public')))
app.listen(PORT, () => {
console.info('Application started at %s on port %d',
(new Date()).toString(), PORT);
})