-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
45 lines (36 loc) · 1.08 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
const express = require('express'),
app = express(),
session = require('express-session'),
http = require('http');
server = http.createServer(app),
bodyParser = require('body-parser');
const scout = require('./models/scout');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.set('view engine','ejs')
app.use(express.static(__dirname + '/public'));
app.use(session({
secret: "secreto-key",
resave: false,
saveUninitialized: false
}));
const scoutRoutes = require('./routes/scoutRoutes');
const playerRoutes = require('./routes/playerRoutes');
app.get("/", (req,res) => {
if(req.session.uuid){
res.redirect("/player")
}else{
scout.model.findAll().then(scout =>{
res.render("index", {scout:scout});
}).catch(err => {
console.log(err);
})
}
})
app.get("/logout", (req,res)=>{
req.session.destroy();
res.redirect("/");
})
app.use('/scout', scoutRoutes);
app.use('/player', playerRoutes);
server.listen(8080, () => console.log("8080 is the port friends"));