-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (34 loc) · 1000 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
37
38
39
40
41
42
const express = require('express');
const cors = require('cors');
const setupRouter = require('./src/routes/index.js');
const errorHandler = require('./src/middlewares/errorHandling.middlware.js');
const bodyParser = require('body-parser');
const {
logger,
infoLevelLogging,
} = require('./src/middlewares/logging.middleware.js');
require('dotenv').config();
const app = express();
// middlewares
app.use(cors());
app.use(express.json()); // For json format of requests and responses
app.use(express.urlencoded({ extended: true }));
app.use(bodyParser.json()); // For parsing request body
app.use(bodyParser.urlencoded({ extended: true }));
app.use(infoLevelLogging);
// ping api
app.get('/', (req, res) => {
res.json({
message: 'Hello from api',
});
});
// router
setupRouter(app);
// Error hanlding
app.use(errorHandler);
// port
const PORT = process.env.PORT || 8080;
// server
app.listen(PORT, () => {
logger.log('info', `App listening on port ${PORT}!`);
});