-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
80 lines (60 loc) · 2.25 KB
/
server.js
File metadata and controls
80 lines (60 loc) · 2.25 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
//final checked by ramita and radhi (11/08)
const express = require('express');
const mysql = require('mysql2/promise');
const path = require('path');
require('dotenv').config();
const bodyParser = require('body-parser');
const app = express();
const table_name = {
login: "users",
delete_flag: "account_flag",
images: "Images",
handle_privilege: "account_elev",
invoice: "forms",
soa:"forms",
};
const pool = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
});
pool.on('error', (err) => {
console.error('Error in MySQL connection pool:', err);
});
// Increase payload size limit
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.use(bodyParser.json({ limit: '50mb' }));
app.use(express.static('public'));
// Export the pool and table_name for testing purposes
module.exports = { pool, table_name };
// Check if this file is run directly (as the main application)
if (require.main === module) {
// Set up routes and start the server
const accountRouter = require('./routes/account');
app.use('/account', accountRouter);
const awsRouter = require('./routes/rekognition');
app.use('/rekognition/', awsRouter);
const invoiceRouter = require('./routes/invoice');
app.use('/invoice/', invoiceRouter);
const homepageRouter = require('./routes/homepage');
app.use('/homepage/', homepageRouter);
const paymentRouter = require('./routes/payment'); // Replace the path with the actual path to your payment.js file
app.use('/payment', paymentRouter);
const paidRouter = require('./routes/paid');
app.use('/paid', paidRouter);
const supplierRouter = require('./routes/supplier'); // Replace the path with the actual path to your payment.js file
app.use('/supplier', supplierRouter);
const notificationRouter = require('./routes/notification');
app.use('/notification', notificationRouter);
app.get('*', function (req, res) { // Catch 404 errors
res.status(404).sendFile(path.join(__dirname, 'public', 'html', '404.html'));
});
const port = process.env.PORT;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
}