-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
70 lines (65 loc) · 1.98 KB
/
server.js
File metadata and controls
70 lines (65 loc) · 1.98 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
const moment = require("moment");
const dotenv = require("dotenv");
const cors = require("cors");
const fileUpload = require("express-fileupload");
const { sqlInjectionPrevention } = require("./app/utils");
require("express-group-routes");
dotenv.config();
var express = require("express"),
app = express(),
port = process.env.APP_PORT,
bodyParser = require("body-parser");
app.use(
fileUpload({
createParentPath: true,
})
);
app.use(cors());
// app.use(bodyParser.json());
// app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
// LOAD MIDDLEWARE OAUTH
var middleware = require("./app/middleware/middleware");
app.use(async function (req, res, next) {
// Create log for request
let request = {
currentTime:
moment().format("Y-MM-D") + " " + moment().format("HH:mm:ss:SSS"),
client_ip: req.headers["x-forwarded-for"] || req.ip,
method: req.method,
path: req.originalUrl,
body: req.body,
};
console.log("======================================================");
console.log(`req : ${JSON.stringify(request)}`);
// PREVENT FROM SQL INJECTION
if (req.method === "GET") {
req.query = sqlInjectionPrevention(req.query);
} else {
req.body = sqlInjectionPrevention(req.body);
}
if (
req.originalUrl == "/api/administrator/login/user" ||
req.originalUrl.includes("/api/administrator/generate-barcode") ||
(req.originalUrl == "/api/administrator/configuration" &&
req.method == "GET")
) {
next();
return;
}
let check_token = await middleware.check_token(req, res);
let create_log = true;
if (check_token && req.method != "GET") {
create_log = await middleware.create_log(req, res);
}
if (check_token && create_log) {
next();
return;
}
});
// END MIDDLEWARE OAUTH
var routes = require("./app/routes");
routes(app);
app.listen(port);
console.log(`${process.env.APP_NAME} started on port: ${port}`);