-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
150 lines (109 loc) · 3.96 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
require('dotenv').config()
// const loginController = require('./controllers/loginController');
// const signupController = require('./controllers/signupController');
// const indexController = require('./controllers/indexController');
// const transactionsController = require('./controllers/transactionsController');
// const auth = require('./validation/authValidation')
// const initPassportLocal = require('./controllers/passportLocalController');
const initWebRoutes = require('./routes/web');
const pool = require('./configs/database');
const express = require('express');
const app = express();
const path = require('path');
const ejsMate = require('ejs-mate');
const mysql = require('mysql');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const connectFlash = require('connect-flash');
const session = require('express-session');
const passport = require('passport');
app.engine('ejs', ejsMate);
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'))
app.use(express.static(__dirname + '/public'));
//Enable body parser post data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(cookieParser('secret'));
//config session
app.use(session({
secret: 'secret',
resave: true,
saveUninitialized: false,
cookie: {
maxAge: 1000 * 60 * 60 * 24 // 86400000 1 day
}
}));
//Enable flash message
app.use(connectFlash());
app.use(express.json());
// app.use((req,res,next) => {
// res.locals.currentUser = req.user;
// console.log("on app..", req.user);
// next();
// })
// app.get('/dogs', async(req,res) => {
// const ensureSchema = async pool => {
// // Wait for tables to be created (if they don't already exist).
// await pool.query(
// `CREATE TABLE IF NOT EXISTS votes
// ( vote_id SERIAL NOT NULL, time_cast timestamp NOT NULL,
// candidate CHAR(6) NOT NULL, PRIMARY KEY (vote_id) );`
// );
// console.log("Ensured that table 'votes' exists");
// };
// });
// const pool = mysql.createPool({
// host: process.env.DB_HOST,
// user: process.env.DB_USER,
// password: process.env.DB_PASS,
// database: process.env.DB_DATABASE,
// });
// app.get("/", async(req, res) => {
// pool.getConnection((err, connection) => {
// console.log('connected as id ' + connection.threadId);
// connection.query('SELECT * FROM users', (err, rows) => {
// connection.release(); //return the connection to pool
// if(err) throw err;
// console.log('The data from users table are: \n', rows);
// });
// });
// });
app.get('/status', (req,res) => res.send('Working!'));
// app.get('/', async(req, res) => {
// res.render('index')
// //res.json({status: "BARK BARK!!"});
// })
// app.get('/', loginController.checkLoggedIn, indexController.getIndexPage);
// app.get('/transactions', (req,res) => {
// res.render('transactions')
// })
// app.get('/transactions', transactionsController.getTransactionsPage);
// app.get('/login', (req,res) => {
// res.render('login')
// })
// app.get('/login', loginController.checkLoggedOut, loginController.getLoginPage);
// app.post('/login', passport.authenticate("local", {
// successRedirect: "/",
// failureRedirect: "/login",
// successFlash: true,
// failureFlash: true
// }));
// // app.get('/signup', (req, res) => {
// // res.render('signup')
// // })
// app.get('/signup', signupController.getSignupPage);
// app.post('/signup', auth.validateSignup, signupController.createNewUser);
// app.post('/logout', loginController.postLogOut);
// app.listen(8080, () => {
// console.log('ON PORT 8080');
// })
//Config passport middleware
app.use(passport.initialize());
app.use(passport.session());
// init all web routes
initWebRoutes(app);
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log(`RUNNING ON PORT ${port}`);
})