generated from CodeChefVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
47 lines (40 loc) · 1.26 KB
/
index.js
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
const express = require("express");
const mongoose = require("mongoose");
const morgan = require("morgan");
const os = require("os");
const cors = require("cors");
const TestCaseRouter = require("./api/routes/testCaseRouter");
const authRoute = require("./api/routes/auth");
const quesRoute = require("./api/routes/questionsRouter");
const adminRoute = require("./api/routes/adminRouter");
const subroute = require("./api/routes/submission");
require("dotenv").config();
const app = express();
// Read MongoDB connection details from environment variables
const mongoURI = process.env.DB_URI;
console.log(mongoURI);
// Connecting to mongoDB
mongoose
.connect(mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("MongoDB Connected"))
.catch((err) => console.log(err));
// Using middleware
app.use(express.json());
app.use(morgan("tiny"));
app.use(cors());
// Setting up routes
app.get("/ping", (_, res) => {
res.status(200).json({ msg: "pong", hostname: os.hostname() });
});
app.use("/testcases/", TestCaseRouter);
app.use("/auth/", authRoute);
app.use("/ques/", quesRoute);
app.use("/submit/", subroute);
app.use("/admin/", adminRoute);
// Starting Server
app.listen(8080, () => {
console.log("Server started at port: 8080");
});