-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
37 lines (30 loc) · 983 Bytes
/
index.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
import express from 'express';
import importMiddlewares from './server/config/middlewaresConfig.js';
import { connect } from './server/config/serverConfig.js';
import { errorHandler } from './server/helpers/errorHandler.js';
import apiRouthes from './server/config/endpointsConfig.js';
import envConfig from './server/config/envConfig.js';
//config
const app = express();
const PORT = process.env.PORT;
export const JWT_TOKEN = envConfig.JWT;
// importing middlewares
const middlewares = await importMiddlewares();
middlewares.forEach((middleware) => {
app.use(middleware);
});
// importing routes
for (const controller of apiRouthes) {
app.use(controller.route, controller.controller);
}
// error middleware for undefined routes
app.use((req, res, next) => {
res.status(404).json({ message: 'Route not found' });
});
// error Handler for custom errors
app.use(errorHandler);
// server
app.listen(PORT, () => {
connect();
console.log('conected to port' + PORT);
});