Browse Source

Phase III Task 2 Complete

master
Yutsuo 7 years ago
parent
commit
d7cb9a2268
  1. 20
      docker-compose.yml
  2. 5
      nginx2/Dockerfile
  3. 2
      nginx2/html/index.html
  4. 8
      nginx2/html/nay.html
  5. 8
      nginx2/html/yay.html
  6. 11
      nginx2/nginx.conf
  7. 19
      node/app.js

20
docker-compose.yml

@ -3,21 +3,25 @@ version: '3'
services:
nginx:
container_name: nginx
depends_on:
- app
# depends_on:
# - app
restart: always
build: ./nginx
image: custom/nginx
ports:
- 80:80
# ports:
# - 80:80
links:
- app
- prometheus
networks:
- network_1
nginx2:
container_name: nginx2
restart: always
image: nginx
expose:
- "80"
build: ./nginx2
image: custom/nginx2
ports:
- 80:80
networks:
- network_1
app:
@ -27,6 +31,8 @@ services:
restart: always
build: ./node
image: custom/node
ports:
- 3001:3001
networks:
- network_1
# - network_2

5
nginx2/Dockerfile

@ -0,0 +1,5 @@
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY ./html/ /data/www/

2
nginx2/index.html → nginx2/html/index.html

@ -5,7 +5,7 @@
<div class="form-header" style="background-color:black; color:white; padding:20px; left:50%; ">
<h2>Authenticate thyself</h2>
</div>
<form method="post" action="/token" novalidate>
<form method="post" action="http://localhost:3001/token" novalidate>
<div class="form-field" style="background-color:black; color:white; padding:20px; left:50%; ">
<label for="message">Username</label>
<input class="input" id="username" name="username" autofocus >

8
nginx2/html/nay.html

@ -0,0 +1,8 @@
<body>
<div>
<h1>THOUS HAST FAILED</h1>
</div>
<h2>BEGONE FROM MY LAIR, MORTAL</h2>
</div>
</form>
</body>

8
nginx2/html/yay.html

@ -0,0 +1,8 @@
<body>
<div>
<h1>THOUS HAST SUCCEEDED</h1>
</div>
<h2>THOU ART LOGGED</h2>
</div>
</form>
</body>

11
nginx2/nginx.conf

@ -0,0 +1,11 @@
worker_processes 1;
events { worker_connections 1024; }
http {
server {
location / {
root /data/www;
}
}
}

19
node/app.js

@ -9,6 +9,7 @@ const Prometheus = require('prom-client');
const fs = require('file-system');
const marked = require('marked');
const jwt = require('jsonwebtoken');
const bodyParser= require('body-parser');
// database connection (with retries)
const options = {
@ -84,7 +85,8 @@ app.get('/metrics2', function(req, res){
})
// JWT generation
app.use(express.json());
// app.use(express.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/token', function(req, res){
console.log(req.body);
console.log(req.body.username);
@ -94,15 +96,18 @@ app.post('/token', function(req, res){
var token = jwt.sign(req.body, 'wowmuchsecretveryhiddenwow');
console.log(token);
// res.json(token);
res.status(200).json({
success: 'SUCCESS! You\'re in.',
token: token
});
// res.status(200).json({
// success: 'SUCCESS! You\'re in.',
// token: token
// });
res.redirect('http://localhost/yay.html');
} else {
res.status(500).send('this is not the password I expected');
// res.status(500).send('this is not the password I expected');
res.redirect('http://localhost/nay.html');
}
} else {
res.status(500).send('this is not the user I want');;
// res.status(500).send('this is not the user I want');
res.redirect('http://localhost/nay.html');
}
});

Loading…
Cancel
Save