-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
124 lines (97 loc) · 3.72 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const fs = require('fs');
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const cors = require('cors');
const Users = require('./model/user');
const https = require('https')
const session = require('express-session')
require('dotenv').config();
console.log('mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm');
mongoose.connection.on('error', (err) => {
console.log('Erro na conexão com o banco de dados: ', err);
})
mongoose.connection.on('disconnect', () => {
console.log('Aplicação desconectada do banco de dados!')
})
mongoose.connection.on('connected', () => {
console.log('Aplicação conectada ao banco de dados!')
})
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}))
app.use(cors());
app.use(express.json());
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 }))
/* Middlewares */
// app.use(bodyParser.json())
// app.use('/doc', swaggerUi.serve, swaggerUi.setup(swaggerFile))
//Body Parser
// app.use(bodyParser.urlencoded({ extended: false }));
// app.use(bodyParser.json());
// app.use(express.bodyParser({limit: '50mb'}));
// app.use(express.json());
// app.use(express.json({limit: '50mb'}));
// app.use(express.urlencoded({limit: '50mb'}));
const indexRoute = require('./Routes/index')
const usersRoute = require('./Routes/users')
const mensagemRoute = require('./Routes/mensagens');
const temaRoute = require('./Routes/temas');
const propostasRoute = require('./Routes/propostas');
const propostaComentariosRoute = require('./Routes/propostacomentarios');
const propostaModeracaoRoute = require('./Routes/propostamoderacao');
const moderacaoRoute = require('./Routes/moderacoes');
const numerosRoute = require('./Routes/numeros');
const reunioesRoute = require('./Routes/reunioes');
const estatisticasRoute = require('./Routes/estatisticas');
const apimatomoRoute = require('./Routes/apismatomo');
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger-output.json');
//Uso do swagger
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
// mongoose.connect(
// 'mongodb://db/http_app',
// {useNewUrlParser: true, useUnifiedTopology: true });
mongoose.connect(
'mongodb://127.0.0.1:27017/http_app',
{useNewUrlParser: true, useUnifiedTopology: true });
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/', indexRoute);
app.use('/users', usersRoute);
app.use('/mensagens', mensagemRoute);
app.use('/temas', temaRoute);
app.use('/propostas', propostasRoute);
app.use('/propostacomentarios', propostaComentariosRoute);
app.use('/propostamoderacao', propostaModeracaoRoute);
app.use('/moderacoes', moderacaoRoute);
app.use('/numeros', numerosRoute);
app.use('/reunioes', reunioesRoute);
app.use('/estatisticas', estatisticasRoute);
app.use('/apimatomo', apimatomoRoute);
const options = {
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt'),
};
https.createServer(
// {
// key: fs.readFileSync('server.key'),
// cert: fs.readfileSync('server.crt')
// }
options ,
app
).listen(4040, () => console.log("App disponível em https:// Server is running - port 4040"));
// const options = {
// key: fs.readFileSync('server.key'),
// cert: fs.readFileSync('server.crt'),
// };
// https.createServer(options, (req, res) => {
// res.writeHead(200);
// res.end(`hello world\n`);
// }, app ).listen(4040, () => console.log("App disponível em https:// Server is running - port 4040"));
module.exports = app;