forked from mendhak/docker-http-https-echo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (38 loc) · 914 Bytes
/
index.js
File metadata and controls
42 lines (38 loc) · 914 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
38
39
40
41
42
var express = require('express')
const morgan = require('morgan');
var app = express()
const os = require('os');
const jwt = require('jsonwebtoken');
app.set('json spaces', 2);
app.use(morgan('combined'));
app.all('*', (req, res) => {
const echo = {
path: req.path,
headers: req.headers,
method: req.method,
body: req.body,
cookies: req.cookies,
fresh: req.fresh,
hostname: req.hostname,
ip: req.ip,
ips: req.ips,
protocol: req.protocol,
query: req.query,
subdomains: req.subdomains,
xhr: req.xhr,
os: {
hostname: os.hostname()
}
};
if (process.env.JWT_HEADER) {
const token = req.headers[process.env.JWT_HEADER.toLowerCase()];
if (!token) {
echo.jwt = token;
} else {
const decoded = jwt.decode(token, {complete: true});
echo.jwt = decoded;
}
}
res.json(echo);
})
app.listen(process.env.PORT || 80)