-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (49 loc) · 1.39 KB
/
index.js
File metadata and controls
57 lines (49 loc) · 1.39 KB
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
const express = require('express');
const mysql = require('mysql2/promise');
const bodyParser = require('body-parser');
const session = require('express-session');
const account = require('./account');
const admin = require('./admin');
const groups = require('./groups');
const app = express();
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }))
app.use(session({
secret: 'fullstack-academy',
resave: true,
saveUninitialized: true
}));
app.set('view engine', 'ejs');
const init = async() => {
const connection = await mysql.createConnection({
host: '127.0.0.1',
user: 'futiba',
password: 'futibaclub',
database: 'futibaclub'
});
app.use((req, res, next) => {
if(req.session.user){
res.locals.user = req.session.user;
}else{
res.locals.user = false;
};
next();
});
app.use(account(connection));
app.use('/admin', admin(connection));
app.use('/groups', groups(connection));
// Rota para criar 30000 usuário
app.get('/create-user', async(req, res) => {
const min = 1;
const max = 30000;
//const rand = min + Math.random() * (max - min);
for(let i = min; i < max; i++){
console.log(parseInt(min + Math.random() * (max - min)));
};
res.redirect('/');
});
app.listen(3000, err => {
console.log('Futiba Club Server in running...')
});
};
init();