-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
36 lines (29 loc) · 918 Bytes
/
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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const connectDB = require('./config/db');
const path = require("path");
const expressPinoLogger = require('express-pino-logger');
const loggerService = require('./services/logger.service')
const mainRoute = require('./routes/main.routes')
const PORT = 8080;
const app = express();
// Allow CORS from all domains
app.use(cors({
origin: '*'
}));
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.use(express.static(`${__dirname}/public`));
// Pino logger
const loggerMiddleware = expressPinoLogger({
logger: loggerService,
autoLogging: true,
});
app.use(loggerMiddleware);
app.use(express.json());
app.use(cors());
// Define Routes Below
app.use('/api/main', mainRoute)
connectDB();
app.listen(PORT, () => console.log(`Server is running 🔥 on http://localhost:${PORT}`));