-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
127 lines (113 loc) · 4.89 KB
/
app.js
File metadata and controls
127 lines (113 loc) · 4.89 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var http = require('http');
var url = require('url');
var express = require('express');
var nconf = require('nconf');
var path = require('path');
const static_folder = "/static";
const static_folder_html = "/static/html";
nconf.file( {file: './config/webapp-template-config.json'});
const objUserAuth = require('./services/userAuthentication');
const objUserMgmt = require('./services/userManagement');
var app = express();
//app.use('/assets', express.static(__dirname + '/static/html'));
app.use(express.json());
//########## URLs mapping ##########
//__dirname : It will be resolved to your project folder.
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + static_folder + '/html/index.html'));
});
app.get('/css/*', function (req, res) {
var filename = url.parse(req.url).pathname;
res.sendFile(path.join(__dirname + static_folder + filename));
});
app.get('/img/*', function (req, res) {
var filename = url.parse(req.url).pathname;
res.sendFile(path.join(__dirname + static_folder + filename));
});
app.get('/fonts/*', function (req, res) {
var filename = url.parse(req.url).pathname;
res.sendFile(path.join(__dirname + static_folder + filename));
});
app.get('*.html', function (req, res) {
var filename = url.parse(req.url).pathname;
res.sendFile(path.join(__dirname + static_folder_html + filename));
});
app.get('/lib-js/*', function (req, res) {
var filename = url.parse(req.url).pathname;
res.sendFile(path.join(__dirname + static_folder + filename));
});
//Must be placed below lib-js so both js library files and individual js scripts can be loaded
app.get('*.js', function (req, res) {
var filename = url.parse(req.url).pathname;
res.sendFile(path.join(__dirname + static_folder_html + filename));
});
//########## APIs mapping ##########
//##### User Authentication #####
app.post('/api/doLogin', async function (req, res) {
res.json(await objUserAuth.doLogin(req.body, req.headers['user-agent']));
});
app.post('/api/doLogoff', async function (req, res) {
res.json(await objUserAuth.doLogoff(req.body, req.headers['user-agent']));
});
app.post('/api/doSendPasswordResetEmail', async function (req, res) {
res.json(await objUserAuth.doSendPasswordResetEmail(req.body));
});
app.post('/api/doResetPassword', async function (req, res) {
res.json(await objUserAuth.doResetPassword(req.body));
});
app.post('/api/doFetchRequestDetails', async function (req, res) {
res.json(await objUserAuth.doFetchRequestDetails(req.body));
});
//##### Email Landing URLs #####
app.get('/email/doResetPasswordRequest/:requestId', async function (req, res) {
var validRequest = await objUserAuth.doPwdResetRequesValidation(req.params.requestId);
res.writeHead(301, {
'location': 'http://localhost:2509',
'Set-Cookie': ['pwdResetReqId=' + req.params.requestId + ';path=/','pwdResetReqIdStatus=' + validRequest + ';path=/'],
});
validRequest = null;
res.end();
});
app.get('/email/doAccountVerificationRequest/:requestId', async function (req, res) {
var validRequest = await objUserMgmt.doAccountVerificationRequesValidation(req.params.requestId);
res.writeHead(301, {
'location': 'http://localhost:2509',
'Set-Cookie': ['accVerificationReqId=' + req.params.requestId + ';path=/', 'accVerificationReqIdStatus=' + validRequest + ';path=/'],
});
validRequest = null;
res.end();
});
//##### User Management #####
app.post('/api/doCreateUser', async function (req, res) {
res.json(await objUserMgmt.doCreateUser(req.body));
});
app.post('/api/doUpdateUser', async function (req, res) {
res.json(await objUserMgmt.doUpdateUser(req.body));
});
app.post('/api/doUpdateUserPassword', async function (req, res) {
res.json(await objUserMgmt.doUpdateUserPassword(req.body));
});
app.post('/api/doValidateEmail', async function (req, res) {
res.json(await objUserMgmt.doValidateEmail(req.body));
});
app.post('/api/doSendAccountVerificationEmail', async function (req, res) {
res.json(await objUserMgmt.doSendAccountVerificationEmail(req.body));
});
app.get('/api/doFetchUsersList', function (req, res) {
res.json(objUserMgmt.doFetchUsersList(req.body));
});
app.get('/api/doFetchUserDeviceList', function (req, res) {
res.json(objUserMgmt.doFetchUserDeviceList(req.headers['userid'], req.headers['authenticationtoken']));
});
app.get('/api/doFetchUserSessionList', function (req, res) {
res.json(objUserMgmt.doFetchUserSessionList(req.headers['userid'], req.headers['authenticationtoken']));
});
app.get('/api/doFetchUsersDetail', function (req, res) {
res.json(objUserMgmt.doFetchUsersDetail(req.body));
});
var port = process.env.PORT || nconf.get('app_parameters:tcp_port');
var port = nconf.get('app_parameters:tcp_port');
process.title = 'webapp template running on node.js';
console.log("Starting webapp template service...");
app.listen(port);
console.log("webapp template started on port " + port);