-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (24 loc) · 858 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
require('express-async-errors');
const CustomError = require('./helpers/CustomError');
const config = require('./config');
const http = require('http');
const app = require('express')();
const server = http.createServer(app);
const cors = require('cors');
const middlewares = require('./middlewares');
const errorHandler = require('./middlewares/errorHandler');
const routes = require('./routes');
const databaseConfig = require('./config/db');
app.use(cors());
middlewares(app);
app.use('/api', routes());
app.use((req, res, next) => {
const error = new CustomError(`${req.method} to ${req.url} not found`, 404);
next(error);
});
app.use(errorHandler);
server.listen(config.port, () => {
console.log(`:: server listening on port ${config.port}`);
databaseConfig();
});
// server.on('error', (error) => { console.log(`:: error: ${error}`); });