-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
54 lines (46 loc) · 1.43 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
54
import dotenv from "dotenv";
import express from 'express';
import helmet from "helmet";
import expressWinston from "express-winston";
import winstonLogger from "./winston/logger";
const dbConnection = require('./db.connection/dbconnection')
const userController = require("./controller/user.controller");
const recipiController = require("./controller/recipi_menu.controller")
const forgotPassword = require("./controller/forgot_password")
const port: number = parseInt(process.env.PORT || "3000");
const app = express();
dotenv.config();
app.use(helmet());
//to get json(object) response
app.use(express.json());
// winston logger
app.use(expressWinston.logger({
winstonInstance: winstonLogger,
}));
//router connection
app.use("/api/user", userController);
app.use("/api/recipi", recipiController);
app.use("/api/forgot-password",forgotPassword);
//ERROR HANDLING
app.use((err:any, req:any, res:any, next:any) => {
winstonLogger.error("error===>>",err)
//winstonLogger.info("logger",err)
if (err.message == "jwt expired") {
return res.status(403).send({
message: "Bad jwt Token",
});
}
return res.status(500).send({
message: "internal server error",
});
});
//DB CONNECTION
dbConnection.dbConnect();
if (!process.env.PORT) {
console.error("PORT environment variable is not set.");
process.exit(1);
}
// port listening
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});