-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
87 lines (75 loc) · 2.85 KB
/
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
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
const express = require("express");
const http = require("http");
const bodyParser = require("body-parser");
const path = require("path");
const logger = require("heroku-logger");
const cors = require("cors");
const passport = require("passport");
const compression = require("compression");
const forceSsl = require('force-ssl-heroku');
const perguntas = require("./server/routes/api/perguntas");
const auth = require("./server/routes/api/auth");
const usuarios = require("./server/routes/api/usuarios");
const temas = require("./server/routes/api/temas");
const alinhamento = require("./server/routes/api/alinhamento");
const comissoes = require("./server/routes/api/comissoes");
const parlamentares = require("./server/routes/api/parlamentares");
const aderencia = require("./server/routes/api/aderencia");
const orientacoes = require("./server/routes/api/orientacoes");
const liderancas = require("./server/routes/api/liderancas");
const perfil = require("./server/routes/api/perfil");
const investimentoPartidario = require("./server/routes/api/investimentoPartidario");
const buscaParlamentar = require("./server/routes/api/busca-parlamentar");
const votacoes = require("./server/routes/api/votacoes");
const swagger = require("./server/routes/api/swagger");
const app = express();
app.use(forceSsl);
app.use(compression());
var db = require("./server/models/index");
const corsOptions = {
origin: [
/localhost:.*/,
/.*\.parlametria\.org\.br$/
],
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true,
allowedHeaders: ["Content-Type", "Authorization"],
exposedHeaders: ["authorization"]
};
app.use(cors(corsOptions));
// Body parser middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(passport.initialize());
app.use(bodyParser.json());
// Testa conexão com o BD
db.sequelize
.authenticate()
.then(() => {
logger.info("Conexão com BD estabelecida com sucesso.");
})
.catch(err => {
logger.error("Não foi possível conectar com o BD: ", err);
});
// Usar as rotas
app.use("/api/perguntas", perguntas);
app.use("/api/usuarios", usuarios);
app.use("/api/auth", auth);
app.use("/api/temas", temas);
app.use("/api/alinhamento", alinhamento);
app.use("/api/comissoes", comissoes);
app.use("/api/parlamentares", parlamentares);
app.use("/api/aderencia", aderencia);
app.use("/api/orientacoes", orientacoes);
app.use("/api/liderancas", liderancas);
app.use("/api/perfil", perfil);
app.use("/api/investimento", investimentoPartidario);
app.use("/api/busca-parlamentar", buscaParlamentar);
app.use("/api/votacoes", votacoes);
app.use("/api/swagger", swagger);
// Set static folder
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
const port = process.env.PORT || 5000;
app.listen(port, () => logger.info(`Servidor rodando na porta ${port}`));