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: services:
nginx: nginx:
container_name: nginx container_name: nginx
replicas: 3 deploy:
replicas: 3
restart: always restart: always
build: ./nginx build: ./nginx
image: custom/nginx image: custom/nginx
@ -16,7 +17,8 @@ services:
- network_1 - network_1
app: app:
container_name: app container_name: app
replicas: 5 deploy:
replicas: 6
build: ./node build: ./node
image: custom/node image: custom/node
volumes: volumes:

4
nginx/html/index.html

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

23
nginx/html/test.html

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

3
node/app.js

@ -230,7 +230,6 @@ restrictedRoutes.all('/', function(req, res, next) {
}) })
restrictedRoutes.use(function (req, res, next) { restrictedRoutes.use(function (req, res, next) {
// let hostname = os.hostname()
res.setHeader('HOSTNAME', os.hostname()) 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) {
@ -259,9 +258,7 @@ restrictedRoutes.use(function (req, res, next) {
// Restricted endpoint // Restricted endpoint
restrictedRoutes.get('/', (req, res) => { 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).json([{secret:'You have access to restricted contents!'}])
// res.status(200).send(successMsg)
console.log(JSON.stringify({secret:'You have access to restricted contents!'})) 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('why, though');
console.log(Object.values(data)); console.log(Object.values(data));
console.log(Object.keys(data)); console.log(Object.keys(data));
console.log(res.headers)
}) })
}) })

Loading…
Cancel
Save