-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
55 lines (46 loc) · 1.6 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
50
51
52
53
import bodyParser from "body-parser";
import morgan from "morgan";
import express, { Application, Request, Response } from "express";
import mongoose from "mongoose";
import dotenv from "dotenv";
import commentRoutes from "./src/Routes/commentRoutes";
import userRoutes from "./src/Routes/UserRoute";
import blogRoutes from "./src/Routes/BlogRoute";
import contactUsRoutes from "./src/Routes/contactUsRoutes";
import subscribeRoutes from "./src/Routes/subscribeRoute";
import swaggerUI from "swagger-ui-express";
import swaggerJSDoc from "swagger-jsdoc";
import cors from "cors";
import helmet from "helmet";
import { options } from "./src/Docs/basicInfo";
dotenv.config();
mongoose.set("strictQuery", false);
mongoose
.connect(process.env.MONGODB_URL as string)
.then(() => {
console.log("DB CONNECTED");
})
.catch((err: Error) => {
console.log(err);
});
const app: Application = express();
const specs = swaggerJSDoc(options)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
app.use(helmet());
app.use(morgan("dev"));
app.use('/api/user', userRoutes);
app.use('/api/blog', blogRoutes);
app.use('/api/comlike', commentRoutes);
// import basicInfo from './basicInfo';
app.use('/api/contactus', contactUsRoutes);
app.use('/api/subscribe', subscribeRoutes);
app.use('/api-docs',swaggerUI.serve,swaggerUI.setup(specs));
app.get("/", (req: Request, res: Response) => {
return res.json({ message: "Welcome To My portfolio API" });
});
const PORT: number = Number(process.env.PORT);
app.listen(PORT, () => {
console.log(`The Server is connected on ${PORT}`);
});