Browse Source

Phase III Task 6

master
Yutsuo 7 years ago
parent
commit
fb0a492cba
  1. 6
      docker-compose.yml
  2. 4
      nginx/html/index.html
  3. 23
      nginx/html/test.html
  4. 3
      node/app.js
  5. 1
      node/html/yay.html

6
docker-compose.yml

@ -3,7 +3,8 @@ version: '3'
services:
nginx:
container_name: nginx
replicas: 3
deploy:
replicas: 3
restart: always
build: ./nginx
image: custom/nginx
@ -16,7 +17,8 @@ services:
- network_1
app:
container_name: app
replicas: 5
deploy:
replicas: 6
build: ./node
image: custom/node
volumes:

4
nginx/html/index.html

@ -1,3 +1,4 @@
<html>
<meta charset="UTF-8">
<body>
<div>
@ -19,4 +20,5 @@
<button class="btn" type="submit">LOGIN</button>
</div>
</form>
</body>
</body>
</html>

23
nginx/html/test.html

@ -1,22 +1,22 @@
<script>
function getAPI(){
fetch('http://localhost:3001/')
fetch('http://localhost:3001/restricted')
.then(function (res){
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));
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)
})
})
}
</script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
@ -26,5 +26,12 @@
<body onload="getAPI()">
<h1>HTML calling REST API</h1>
<div id="output"></div>
<div>
<button type="button"
onclick="document.getElementById('here').innerHTML=location.hostname">
HOSTNAME
</button>
<p id="here"></p>
</div>
</body>
</html>

3
node/app.js

@ -230,7 +230,6 @@ restrictedRoutes.all('/', function(req, res, next) {
})
restrictedRoutes.use(function (req, res, next) {
// let hostname = os.hostname()
res.setHeader('HOSTNAME', os.hostname())
if (req.cookies.token) {
jwt.verify(req.cookies.token, secret, function (err, decoded) {
@ -259,9 +258,7 @@ restrictedRoutes.use(function (req, res, next) {
// Restricted endpoint
restrictedRoutes.get('/', (req, res) => {
// let successMsg = JSON.stringify({secret:'You have access to restricted contents!'})
res.status(200).json([{secret:'You have access to restricted contents!'}])
// res.status(200).send(successMsg)
console.log(JSON.stringify({secret:'You have access to restricted contents!'}))
})

1
node/html/yay.html

@ -11,6 +11,7 @@
console.log('why, though');
console.log(Object.values(data));
console.log(Object.keys(data));
console.log(res.headers)
})
})

Loading…
Cancel
Save