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
import bodyParser from "body-parser";
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import mongoose from "mongoose";
import multer from "multer";
//swagger doc
import swaggerJsdoc from "swagger-jsdoc";
import swaggerUi from "swagger-ui-express";
const swaggerOptions = {
swaggerDefinition: {
info: {
title: "Sign Connect Plus API Documentation",
version: "1.0.0",
description: "Documentation for Sign Connect Plus Node Backend API",
},
basePath: "/rest_node", // Specify the base path of your API
},
apis: [
"./routes/curriculum.routes.js",
"./routes/feedback.routes.js",
"./routes/leaderboard.routes.js",
"./routes/marksCalculator.routes.js",
"./routes/translate.routes.js",
"./routes/tutorial.routes.js",
"./routes/user.routes.js",
"./routes/userProgress.routes.js",
],
};
const swaggerSpec = swaggerJsdoc(swaggerOptions);
// Set up storage for uploaded images
const storage = multer.memoryStorage();
const upload = multer({ storage: storage });
//import routes
import curriculumRoutes from "./routes/curriculum.routes.js";
import feedbackRoutes from "./routes/feedback.routes.js";
import leaderboardRoutes from "./routes/leaderboard.routes.js";
import marksCalculatorRoutes from "./routes/marksCalculator.routes.js";
import translateRoutes from "./routes/translate.routes.js";
import tutorialRoutes from "./routes/tutorial.routes.js";
import userRoutes from "./routes/user.routes.js";
import userProgressRoutes from "./routes/userProgress.routes.js";
dotenv.config();
const app = express();
const corsOptions = {
origin: 'http://localhost:3000',
origin: 'http://localhost:3001',
};
app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors(corsOptions));
//end
app.get("/", (req, res) => {
res.json({ message: "Welcome to Server Node" });
});
//implement routes
app.use("/rest_node/ssl", translateRoutes);
app.use("/rest_node/user", userRoutes);
app.use("/rest_node/curriculum", curriculumRoutes);
app.use("/rest_node/tutorial", tutorialRoutes);
app.use("/rest_node/user-progress", userProgressRoutes);
app.use("/rest_node/feedback", feedbackRoutes);
app.use("/rest_node/leaderboard", leaderboardRoutes);
app.use("/rest_node/marks-calculator", marksCalculatorRoutes);
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
const CONNECTION_URL = `mongodb+srv://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@researchmanagement-appl.vzhn4.mongodb.net/?retryWrites=true&w=majority`;
const PORT = process.env.PORT || 5000;
mongoose
.connect(CONNECTION_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
app.listen(PORT, () =>
console.log(`Server Running on port :http://localhost:${PORT}`)
);
})
.catch((error) => {
console.error(error);
process.exit(1);
});
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send("Internal Server Error");
});