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: services:
nginx: nginx:
container_name: nginx container_name: nginx
depends_on: # depends_on:
- app # - app
restart: always restart: always
build: ./nginx build: ./nginx
image: custom/nginx image: custom/nginx
ports: # ports:
- 80:80 # - 80:80
links:
- app
- prometheus
networks: networks:
- network_1 - network_1
nginx2: nginx2:
container_name: nginx2 container_name: nginx2
restart: always restart: always
image: nginx build: ./nginx2
expose: image: custom/nginx2
- "80" ports:
- 80:80
networks: networks:
- network_1 - network_1
app: app:
@ -27,6 +31,8 @@ services:
restart: always restart: always
build: ./node build: ./node
image: custom/node image: custom/node
ports:
- 3001:3001
networks: networks:
- network_1 - network_1
# - network_2 # - 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%; "> <div class="form-header" style="background-color:black; color:white; padding:20px; left:50%; ">
<h2>Authenticate thyself</h2> <h2>Authenticate thyself</h2>
</div> </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%; "> <div class="form-field" style="background-color:black; color:white; padding:20px; left:50%; ">
<label for="message">Username</label> <label for="message">Username</label>
<input class="input" id="username" name="username" autofocus > <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 fs = require('file-system');
const marked = require('marked'); const marked = require('marked');
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const bodyParser= require('body-parser');
// database connection (with retries) // database connection (with retries)
const options = { const options = {
@ -84,7 +85,8 @@ app.get('/metrics2', function(req, res){
}) })
// JWT generation // JWT generation
app.use(express.json()); // app.use(express.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/token', function(req, res){ app.post('/token', function(req, res){
console.log(req.body); console.log(req.body);
console.log(req.body.username); console.log(req.body.username);
@ -94,15 +96,18 @@ app.post('/token', function(req, res){
var token = jwt.sign(req.body, 'wowmuchsecretveryhiddenwow'); var token = jwt.sign(req.body, 'wowmuchsecretveryhiddenwow');
console.log(token); console.log(token);
// res.json(token); // res.json(token);
res.status(200).json({ // res.status(200).json({
success: 'SUCCESS! You\'re in.', // success: 'SUCCESS! You\'re in.',
token: token // token: token
}); // });
res.redirect('http://localhost/yay.html');
} else { } 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 { } 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