diff --git a/nginx2/html/nay.html b/nginx/html/nay.html
similarity index 100%
rename from nginx2/html/nay.html
rename to nginx/html/nay.html
diff --git a/nginx/html/test.html b/nginx/html/test.html
new file mode 100644
index 0000000..6f1bdcf
--- /dev/null
+++ b/nginx/html/test.html
@@ -0,0 +1,43 @@
+
+
+
\ No newline at end of file
diff --git a/nginx2/html/test.js b/nginx/html/test.js
similarity index 100%
rename from nginx2/html/test.js
rename to nginx/html/test.js
diff --git a/nginx2/html/test2.html b/nginx/html/test2.html
similarity index 100%
rename from nginx2/html/test2.html
rename to nginx/html/test2.html
diff --git a/nginx2/html/yay.html b/nginx/html/yay.html
similarity index 82%
rename from nginx2/html/yay.html
rename to nginx/html/yay.html
index ab5e5c0..4bc535d 100644
--- a/nginx2/html/yay.html
+++ b/nginx/html/yay.html
@@ -1,3 +1,4 @@
+
THOUS HAST SUCCEEDED
diff --git a/nginx/nginx.conf b/nginx/nginx.conf
index 44ce238..7ac6bcd 100644
--- a/nginx/nginx.conf
+++ b/nginx/nginx.conf
@@ -3,16 +3,9 @@ worker_processes 1;
events { worker_connections 1024; }
http {
-
- upstream app {
- server app:3001;
- }
-
server {
- listen 80;
-
location / {
- proxy_pass http://app;
+ root /data/www;
}
}
}
\ No newline at end of file
diff --git a/nginx2/Dockerfile b/nginx2/Dockerfile
deleted file mode 100644
index 8f74bfc..0000000
--- a/nginx2/Dockerfile
+++ /dev/null
@@ -1,5 +0,0 @@
-FROM nginx
-
-COPY nginx.conf /etc/nginx/nginx.conf
-
-COPY ./html/ /data/www/
\ No newline at end of file
diff --git a/nginx2/html/test.html b/nginx2/html/test.html
deleted file mode 100644
index 3888b26..0000000
--- a/nginx2/html/test.html
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
JS Bin
-
-
-
TEST HTML calling NodeJS
-
-
-
\ No newline at end of file
diff --git a/nginx2/nginx.conf b/nginx2/nginx.conf
deleted file mode 100644
index 7ac6bcd..0000000
--- a/nginx2/nginx.conf
+++ /dev/null
@@ -1,11 +0,0 @@
-worker_processes 1;
-
-events { worker_connections 1024; }
-
-http {
- server {
- location / {
- root /data/www;
- }
- }
-}
\ No newline at end of file
diff --git a/node/Dockerfile b/node/Dockerfile
index ae6970e..c749069 100755
--- a/node/Dockerfile
+++ b/node/Dockerfile
@@ -11,14 +11,19 @@ COPY .npmrc .npmrc
# This results from the way the Docker image is being built (layers and cache),
# and this is what we should do:
COPY package.json /app
-RUN npm install
+
+# RUN npm install
+RUN ["npm", "install"]
+
COPY . /app
ENV mongousr=myTester
ENV mongopwd=test
-RUN sh check-env.sh
+# RUN sh check-env.sh
+RUN ["sh", "check-env.sh"]
-CMD node app.js
+# CMD node app.js
+CMD ["node", "app.js"]
EXPOSE 3001
diff --git a/node/app.js b/node/app.js
index 8e3b2c6..0df77ec 100755
--- a/node/app.js
+++ b/node/app.js
@@ -1,3 +1,4 @@
+'use strict'
const express = require('express');
const app = express();
const mongoose = require('mongoose');
@@ -12,8 +13,12 @@ const jwt = require('jsonwebtoken');
const bodyParser= require('body-parser');
const secret = 'wowmuchsecretveryhiddenwow';
const cookieParser = require('cookie-parser');
+const cookie = require('cookie');
+const successUrl = 'http://localhost:3002/yay.html';
+const failureUrl = 'http://localhost:3002/nay.html';
app.use(cookieParser());
+app.use(cookie());
// const morgan = require('morgan');
// // use morgan to log requests to the console
@@ -31,6 +36,13 @@ app.use(cookieParser());
// next();
// });
+// setting CORS headers
+app.all('/', function(req, res, next) {
+ res.header("Access-Control-Allow-Origin", "*");
+ res.header("Access-Control-Allow-Headers", "X-Requested-With");
+ next()
+});
+
// database connection (with retries)
const options = {
autoIndex: false, // Don't build indexes
@@ -60,7 +72,7 @@ const libCounter = new Prometheus.Counter({
const libUptime = new Prometheus.Counter({
name: 'lib_upTime',
help: 'uptime A counter of the application\'s uptime in seconds created with prometheus nodejs library.'
-})
+});
console.log('mongousr: ', process.env.mongousr);
console.log('mongopwd: ', process.env.mongopwd);
@@ -84,8 +96,8 @@ var thingies = mongoose.model('thingieName', testSchema);
// Default message for testing
app.get('/', (req, res, next)=>{
- // res.json([{message:'yes, your nodejs app is really running'}]);
- res.send('Oh hay');
+ res.json([{message:'yes, your nodejs app is really running'}]);
+ // res.send('Oh hay' + '\n');
counter++; // for prometheus invocation_count metric
libCounter.inc(); // for prometheus lib_invocation_count metric
console.log('Hello, I\'m inside endpoint \'/\'');
@@ -175,27 +187,27 @@ app.post('/token', function(req, res) {
switch(req.body.username) {
case 'user1':
if (req.body.password === 'pass1') {
- token = jwt.sign(claims_user, secret);
+ let token = jwt.sign(claims_user, secret);
// res.cookie('token',token);
res.setHeader('Set-Cookie', 'token=' + token + '; HttpOnly');
res.setHeader('Set-Cookie', 'Authorization=Bearer ' + token + '; HttpOnly');
console.log('JWT Token: ' + token);
console.log(jwt.decode(token));
- res.redirect('http://localhost/yay.html');
+ res.redirect(successUrl);
} else {
- res.redirect('http://localhost/nay.html');
+ res.redirect(failureUrl);
}
break;
case 'power':
if (req.body.password === 'weak') {
- token = jwt.sign(claims_power, secret);
+ let token = jwt.sign(claims_power, secret);
// res.cookie('token',token);
res.setHeader('Set-Cookie', 'token=' + token + '; HttpOnly');
console.log('JWT Token: ' + token);
console.log(jwt.decode(token));
- res.redirect('http://localhost/yay.html');
+ res.redirect(successUrl);
} else {
- res.redirect('http://localhost/nay.html');
+ res.redirect(failureUrl);
}
break;
default:
@@ -208,7 +220,7 @@ app.post('/token', function(req, res) {
// Restricted route root
const restrictedRoutes = express.Router();
-app.use('/', restrictedRoutes);
+app.use('/restricted', restrictedRoutes);
restrictedRoutes.use(function (req, res, next) {
let sentToken = req.headers['token'];
@@ -263,7 +275,7 @@ restrictedRoutes.use(function (req, res, next) {
// });
// Restricted endpoint
-restrictedRoutes.get('/restricted', (req, res) => {
+restrictedRoutes.get('/', (req, res) => {
// 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);
diff --git a/node/package.json b/node/package.json
index 05a7fbd..a52b114 100755
--- a/node/package.json
+++ b/node/package.json
@@ -22,7 +22,7 @@
"body-parser": "^1.18.3",
"jsonwebtoken": "^8.4.0",
"morgan": "^1.9.1",
- "colors": "^1.3.3",
+ "cookie": "^0.3.1",
"cookie-parser": "^1.4.3"
}
}