-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
40 lines (30 loc) · 830 Bytes
/
app.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
require('dotenv').config()
const createError = require('http-errors');
const express = require('express');
const { logger } = require('./utils');
const { connect } = require('./models');
const router = require('./routes');
const app = express();
// configurando formatos de parâmetros
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// declarando rotas
app.use('/', router);
// caso nenhuma rota de match, redireciona para a 404
app.use(function(_req, _res, next) {
next(createError(404));
});
// error handler
app.use(function(err, _req, res, _next) {
res.status(err.status || 500);
res.json({
sucesso: false,
erro: err.message,
});
});
const porta = 3000;
app.listen(porta, () => {
connect();
logger.info(`Servidor ouvindo na porta ${porta}`);
});
module.exports = app;