-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
60 lines (48 loc) · 1.35 KB
/
server.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
48
49
50
51
52
53
54
55
56
57
58
59
60
require("dotenv").config();
const express = require("express");
const oauthServer = require("./src/controllers/oAuth/server");
const db = require("./src/models");
const publicRoutes = require("./src/routers/public.routes");
const secureRoutes = require("./src/routers/secure.routes");
const expressPinoLogger = require("express-pino-logger");
const logger = require("./src/services/loggerService");
const bodyParser = require("body-parser");
const PORT = process.env.PORT || 3000;
let cors = require("cors");
const app = express();
//cors enabling
app.use(cors());
//read json and form data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// pino logger
const loggerMidlleware = expressPinoLogger({
logger,
autoLogging: true,
});
// const loggerMidlleware = pino({
// logger: logger,
// autoLogging: true,
// prettyPrint: {
// levelFirst: true
// }
// })
app.use(loggerMidlleware);
//ROUTES
app.use("/public", publicRoutes);
app.use(
"/secure",
(req, res, next) => {
return next();
},
oauthServer.authenticate(),
secureRoutes
);
try {
db.sequelize.authenticate();
logger.info("Connection has been established successfully.");
} catch (error) {
logger.info(error.stack);
logger.error("Unable to connect to the database:", error);
}
app.listen(PORT, () => logger.info(`Listening on port: ${PORT}`));