-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWebServerGateway.js
More file actions
84 lines (64 loc) · 2.59 KB
/
WebServerGateway.js
File metadata and controls
84 lines (64 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const http = require('http');
const express = require('express');
const bodyParser = require('body-parser');
const httpProxy = require('http-proxy'); // TODO: Ensure this is directly registered in package.json
const UIControls = require('./UIControlGroups');
const proxy = httpProxy.createProxyServer({});
const app = express();
const loginServiceProxy = (req, res) => proxy.web(req, res, {target: 'http://localhost:8880'});
const userAdminServiceProxy = (req, res) => proxy.web(req, res, {target: 'http://localhost:9010'});
const encryptServiceProxy = (req, res) => proxy.web(req, res, {target: 'http://localhost:9020'});
const decryptServiceProxy = (req, res) => proxy.web(req, res, {target: 'http://localhost:9030'});
const dataSourceServiceProxy = (req, res) => proxy.web(req, res, {target: 'http://localhost:9040'});
app.set('port', process.env.PORT || 3000);
// app.set('httpsPort', process.env.HTTPS_PORT || 3000);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.use(express.static('views'));
app.use(express.static('downloads'));
// app.use(busboy());
app.use((req, res, next) => {
// TODO: Check for NODE_ENV development
res.set('Access-Control-Allow-Origin', '*');
next();
});
app.get('/login', (req,res, next) => {
TimeNow = new Date();
msg = '\n Login Request recieved at: ' + TimeNow + '\n';
console.log(msg);
const userUIControls = new UIControls();
userUIControls.LoadLoginPage().then( function(data) {
msg = 'Login response: \n' + data;
console.log(msg);
res.writeHead(200, {'Content-Type': 'HTML'});
res.end(data);
}, function(error) {
console.log(error);
});
});
app.get('/authenticate', (req, res) => {
console.log('Attempted login: ' + req.query.login)
loginServiceProxy(req, res);
});
app.post('/createUser', (req, res) => {
console.log('Attempted CreateUser: ' + req.query.login)
userAdminServiceProxy(req, res);
});
app.post('/enCryptData', (req, res) => {
console.log('Attempted Encryption: ' + req.query.login)
encryptServiceProxy(req, res);
});
app.get('/decryptData', (req, res) => {
console.log('Attempted decryption: ' + req.query.login)
decryptServiceProxy(req, res);
});
app.get('/dataSource', (req, res) => {
console.log('Attempted dataSourcing: ' + req.query.login)
dataSourceServiceProxy(req, res);
});
const httpServer = http.createServer(app);
httpServer.listen(app.get('port'), () => {
console.log('App Server listening on: http://localhost:%s', app.get('port'));
});
module.exports = app;