-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
64 lines (60 loc) · 1.92 KB
/
server.js
File metadata and controls
64 lines (60 loc) · 1.92 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
import express from "express";
import dotenv from "dotenv";
import { fileURLToPath } from "url";
import path from "path";
import cors from "cors";
import connectDB from "./Db/dbconnection.js";
import authRoutes from "./routes/auth.js";
import forumRoutes from "./routes/Forum.js";
import chatbotRoutes from "./routes/Chatbot.js";
import ressourcesRoutes from "./routes/ressources.js";
import schedulerRoutes from "./routes/scheduler.js";
import bodyParser from "body-parser";
import helmet from "helmet";
import settingsRoutes from "./routes/userSettings.js";
import multer from "multer";
import { register } from "./controllers/auth.js";
dotenv.config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
app.use(express.json());
app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(helmet());
app.use(helmet.crossOriginResourcePolicy({ policy: "cross-origin" }));
app.use("/assets", express.static(path.join(__dirname, "public/assets")));
// routes with files
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, "public/assets");
},
filename: (req, file, cb) => {
cb(null, file.originalname);
},
});
const upload = multer({ storage });
app.post("/auth/register", upload.single("picture"), register);
// routes
app.use("/auth", authRoutes);
app.use("/Forum", forumRoutes);
app.use("/chatbot", chatbotRoutes);
app.use("/Resources-tracker", ressourcesRoutes);
app.use("/Farm-scheduler", schedulerRoutes);
app.use("/settings", settingsRoutes);
const PORT = process.env.PORT;
connectDB()
.then(() => {
app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
});
})
.catch((err) => {
console.error("Unable to start server:", err);
process.exit(1);
});
app.use(
cors({
origin: "http://localhost:3000",
})
);