-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (55 loc) · 1.6 KB
/
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
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
//Carregando modulos
const express = require("express")
const handlebars = require('express-handlebars')
const bodyParser = require('body-parser')
const path = require('path')
const session = require('express-session')
const flash = require('connect-flash')
const app = express()
const db = require('./database/db')
db.sequelize.sync();
//Configs
//Sessao
app.use(session({
secret: "campeonatodesurf",
resave: true,
saveUninitialized: true,
}))
app.use(flash())
//Middlewares
app.use((req, res, next) => {
res.locals.success_msg = req.flash("success_msg")
res.locals.error_msg = req.flash("error_msg")
res.locals.unique_msg = req.flash("unique_msg")
next()
})
//BodyParser
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json());
//Handlebars->Template engine
app.engine('handlebars', handlebars({ defaultLayout: 'main' }))
app.set('view engine', 'handlebars')
//Public
app.use(express.static(path.join(__dirname, 'public')))
//Rotas
const surfista_route = require('./routes/surfista_route')
const bateria_route = require('./routes/bateria.route')
const onda_route = require('./routes/onda_route')
const notas_route = require('./routes/nota_route')
//Homepage
app.get("/", function (_req, res) {
res.render('homepage')
})
//Interação com os surfistas
app.use('/surfista', surfista_route)
//Interação com a bateria
app.use('/bateria', bateria_route)
//Interação com a onda
app.use('/onda', onda_route)
//Interação com as notas
app.use('/nota', notas_route)
//Outros
const PORT = process.env.PORT || 3000
app.listen(PORT, () => {
console.log(`Servidor rodando na porta ${PORT}.`)
})