-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·73 lines (60 loc) · 1.67 KB
/
Copy pathapp.js
File metadata and controls
executable file
·73 lines (60 loc) · 1.67 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
import path from "path";
// import fs from "fs";
import cluster from "cluster";
import os from "os";
import express from "express";
// import multer from "multer";
import sequelize from "./utilities/database.js";
import helmet from "helmet";
import compression from "compression";
//all routes imported here
const cpu = os.cpus().length;
const port = process.env.PORT || 3300;
const app = express();
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
for (let i = 0; i < cpu; i++) {
cluster.fork();
}
console.log(cpu);
cluster.on("exit", (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
const __dirname = path.resolve();
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(express.static(__dirname));
// app.use(express.static(path.join(__dirname, "uploaded-pdf")));
// multer configuration
// app.use(
// multer({
// storage: fileStorage,
// fileFilter: fileFilter,
// }).single("pdf")
// );
// app.use(
// "/uploaded-pdf",
// express.static(path.join(__dirname, "uploaded-pdf"))
// );
// app.use(
// "/uploaded-image",
// express.static(path.join(__dirname, "testportal-img"))
// );
//All routes entrypoint here
// app.use("/auth", authenticationRoutes);
// app.use("/administrator", administratorRoutes);
app.use(helmet());
app.use(compression());
//central error handler here
// sync with database
sequelize
.sync()
.then(() => {
app.listen(port);
console.log(`✔️ Server listening on port: ${port} ✔️ `);
})
.catch((err) => {
console.log(err);
});
}