-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
107 lines (70 loc) · 2.87 KB
/
index.js
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
const express = require('express')
const helmet = require('helmet')
const createTables = require('./Relations/createRelations');
const dropTables = require('./Relations/dropRelations');
const createTransactionTable = require('./Relations/createTransactionsTable.js')
const dropTransactionTable = require('./Relations/dropTransactionsTable')
const cluster = require('cluster');
const { pid } = require('process');
const insertDummyData = require('./SampleData/dummyData');
const server = express()
const cors = require('cors');
const userAppRouter = require('./routes/userApp');
const adminAppRouter = require('./routes/adminApp');
const userWebRouter = require('./routes/userWeb');
const adminWebRouter = require('./routes/adminWeb');
const {generateKey, generateTransactionKey} = require('./AssymetricKeyPair/key');
const createViews = require('./ViewGenerator/views.js');
const establishConnection = require('./initializeConnection.js');
const insertCollegeData = require('./SampleData/collegeData');
const checkPaymentStatus = require('./TransactionVerifier/verifyTransactions.js');
const numberOfSlaves = 10;
const PORT = 3000;
server.use(helmet())
server.use(express.json());
server.use(cors());
//Routes
server.use('/userApp', userAppRouter);
server.use('/adminApp', adminAppRouter);
server.use('/userWeb',userWebRouter);
server.use('/adminWeb',adminWebRouter);
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
db = establishConnection();
const initializeStep1 = () => {
//Drop command. Please be carefull!!
dropTables(db[0]);
dropTransactionTable(db[1]);
//Creating tables. Please be careful!
createTables(db[0]);
createTransactionTable(db[1]);
//Inserting Sample Data. Please be careful!
insertCollegeData(db[0]);
createViews(db[0], db[1]);
//Key Generator
//generateKey();
//generateTransactionKey();
console.log("initialization Done...");
}
const initializeStep2 = () =>{
insertDummyData(db[0], db[1]);
console.log("initialization Done...");
}
//Please be careful. Dont run this command if you have data in backend.
//initialize();
// Fork workers
for (let i = 0; i < numberOfSlaves; i++) {
cluster.fork();
}
setInterval(checkPaymentStatus, 900000);
}
else{
server.listen(PORT, (err) => {
if(err){
console.log("Error starting server");
}
else{
console.log(`Process ${pid} listening on port ${PORT}`)
}
})
}