diff --git a/node/app.js b/node/app.js index 5952946..769aba1 100755 --- a/node/app.js +++ b/node/app.js @@ -226,11 +226,13 @@ app.use('/restricted', restrictedRoutes) restrictedRoutes.all('/', function(req, res, next) { res.header("Access-Control-Allow-Origin", "*") res.header("Access-Control-Allow-Headers", "X-Requested-With") + let hostname = os.hostname() + res.setHeader('HOSTNAME', hostname) + console.log(hostname) next() }) restrictedRoutes.use(function (req, res, next) { - res.setHeader('HOSTNAME', os.hostname()) if (req.cookies.token) { jwt.verify(req.cookies.token, secret, function (err, decoded) { if (err) { @@ -262,6 +264,12 @@ restrictedRoutes.get('/', (req, res) => { console.log(JSON.stringify({secret:'You have access to restricted contents!'})) }) +restrictedRoutes.get('/hostname', (req, res) => { + let hostname = {hostname: os.hostname()} + res.status(200).json(hostname) + console.log(JSON.stringify(hostname)) +}) + // // Restricted route root stupid // const restrictedRoutes = express.Router() // app.use('/restricted', restrictedRoutes) diff --git a/node/html/yay.html b/node/html/yay.html index f8f450d..26105e4 100644 --- a/node/html/yay.html +++ b/node/html/yay.html @@ -4,21 +4,20 @@ fetch('http://localhost:3001/restricted') .then(function (res){ + var hostname = 'HOSTNAME(container ID): ' + res.headers.get('HOSTNAME') + console.log(hostname) res.json().then(function(data){ - document.getElementById('output').innerHTML = JSON.stringify(data); - console.log(JSON.stringify(data)); - console.log(JSON.stringify(data, ['message'])); - console.log('why, though'); - console.log(Object.values(data)); - console.log(Object.keys(data)); - console.log(res.headers) + document.getElementById('output').innerHTML = JSON.stringify(data) + document.getElementById('hostname').innerHTML = hostname + console.log(JSON.stringify(data)) }) }) - } - + + +

SUCCESS

@@ -27,8 +26,11 @@

YOU ARE LOGGED

-

Also if you see the message below you have access to resctricted content:

+

Access to resctricted content:

+
+

+
\ No newline at end of file