forked from cyclic-software/express-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
46 lines (41 loc) · 1.13 KB
/
app.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
const express = require('express')
const app = express()
const fs = require('fs')
const VERSION_FILENAME='./.git/refs/heads/main'
app.get('/', (req, res) => {
console.log('[hello-world] root handler called')
res
.set('x-powered-by', 'cyclic.sh')
.send('<h1>Hello World, again (from local, Again, one more time)!</h1>')
.end()
})
app.get('/new', (req, res) => {
console.log('[hello-world] root handler called')
res
.set('x-powered-by', 'cyclic.sh')
.send('<h1>NEW Hello World!</h1>')
.end()
})
app.use('*', (req,res) => {
console.log('[hello-world] Star handler called')
let version = 'unknown'
if (fs.existsSync(VERSION_FILENAME)) {
version = fs.readFileSync(VERSION_FILENAME).toString().substr(0,8)
}
res
.set('x-powered-by', 'cyclic.sh')
.json({
msg: "Not strickly part of the hello world but you get the picture.",
version,
at: new Date().toISOString(),
method: req.method,
hostname: req.hostname,
ip: req.ip,
path: req.params[0],
query: req.query,
headers: req.headers,
cookies: req.cookies,
})
.end()
})
module.exports = app