Browse Source

Phase III Task 6

master
Yutsuo 7 years ago
parent
commit
3e7f5aee64
  1. 10
      node/app.js
  2. 22
      node/html/yay.html

10
node/app.js

@ -226,11 +226,13 @@ app.use('/restricted', restrictedRoutes)
restrictedRoutes.all('/', function(req, res, next) { restrictedRoutes.all('/', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*") res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "X-Requested-With") res.header("Access-Control-Allow-Headers", "X-Requested-With")
let hostname = os.hostname()
res.setHeader('HOSTNAME', hostname)
console.log(hostname)
next() next()
}) })
restrictedRoutes.use(function (req, res, next) { restrictedRoutes.use(function (req, res, next) {
res.setHeader('HOSTNAME', os.hostname())
if (req.cookies.token) { if (req.cookies.token) {
jwt.verify(req.cookies.token, secret, function (err, decoded) { jwt.verify(req.cookies.token, secret, function (err, decoded) {
if (err) { if (err) {
@ -262,6 +264,12 @@ restrictedRoutes.get('/', (req, res) => {
console.log(JSON.stringify({secret:'You have access to restricted contents!'})) 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 // // Restricted route root stupid
// const restrictedRoutes = express.Router() // const restrictedRoutes = express.Router()
// app.use('/restricted', restrictedRoutes) // app.use('/restricted', restrictedRoutes)

22
node/html/yay.html

@ -4,21 +4,20 @@
fetch('http://localhost:3001/restricted') fetch('http://localhost:3001/restricted')
.then(function (res){ .then(function (res){
var hostname = 'HOSTNAME(container ID): ' + res.headers.get('HOSTNAME')
console.log(hostname)
res.json().then(function(data){ res.json().then(function(data){
document.getElementById('output').innerHTML = JSON.stringify(data); document.getElementById('output').innerHTML = JSON.stringify(data)
console.log(JSON.stringify(data)); document.getElementById('hostname').innerHTML = hostname
console.log(JSON.stringify(data, ['message'])); console.log(JSON.stringify(data))
console.log('why, though');
console.log(Object.values(data));
console.log(Object.keys(data));
console.log(res.headers)
}) })
}) })
} }
</script> </script>
<html> <html>
<meta charset="UTF-8"> <head>
<meta charset="UTF-8"> </meta>
</head>
<body onload="getAPI()"> <body onload="getAPI()">
<div> <div>
<h1>SUCCESS</h1> <h1>SUCCESS</h1>
@ -27,8 +26,11 @@
<h2>YOU ARE LOGGED</h2> <h2>YOU ARE LOGGED</h2>
</div> </div>
<div> <div>
<h3>Also if you see the message below you have access to resctricted content:</h3> <h3>Access to resctricted content:</h3>
<h3 id="output"></h3> <h3 id="output"></h3>
</div> </div>
<div>
<h3 id="hostname"></h3>
</div>
</body> </body>
</html> </html>
Loading…
Cancel
Save