-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
49 lines (42 loc) · 1.57 KB
/
index.ts
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
import path from "path";
import cors from "cors";
import dotenv from "dotenv";
import morgan from "morgan";
import mongoose from "mongoose";
import compress from "compression";
import methodOverride from "method-override";
import express, { Request, Response } from "express";
dotenv.config();
const app = express();
const port = process.env.PORT || 3300;
const mongo =
process.env.MONGO_URI || "mongodb://localhost:27017/teacher-review";
const corsOptions = { origin: "*", optionssuccessStatus: 200 };
import userRoutes from "./src/routes/user";
import reviewJSONRoutes from "./src/routes/review.json";
import facultyJSONRoutes from "./src/routes/faculty.json";
import facultyHTMLRoutes from "./src/routes/faculty.html";
import reviewHTMLRoutes from "./src/routes/review.html";
import { authToken } from "./src/middleware/auth";
app.use(compress());
app.use(morgan("dev"));
app.use(express.json());
app.use(cors(corsOptions));
app.set("view engine", "ejs");
app.use(methodOverride("_method"));
app.use(express.urlencoded({ extended: true }));
app.set("views", path.join(__dirname, "/src/views"));
app.use("/authenticate", userRoutes);
app.use("/reviews", authToken, reviewJSONRoutes);
app.use("/faculties", authToken, facultyJSONRoutes);
app.use("/review", reviewHTMLRoutes);
app.use("/faculty", facultyHTMLRoutes);
app.use((req: Request, res: Response) =>
res.send({ message: "Teacher Review APi. Coded with ❤️ by IoT Web Team." })
);
mongoose
.connect(mongo)
.then(() =>
app.listen(port, () => console.log(`Server is running on port ${port}`))
)
.catch((err) => console.log(err));