-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
100 lines (75 loc) · 1.87 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
//Importing required libraries
const express = require('express');
const exphbs = require('express-handlebars');
const bodyParser = require('body-parser');
const mysql = require('mysql');
const session = require('express-session');
const app = express();
const port = process.env.PORT || 8000;
app.use(session({
secret: 'secret',
resave: true,
saveUninitialized: true
}));
//Initialing server with public profile
app.use(express.static('public'));
// body parser config
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//Initializing server with handlebars
app.engine('hbs', exphbs.engine({ extname: 'hbs' }));
app.set('view engine', 'hbs');
require('dotenv').config();
//Creating pool connection
const pool = mysql.createPool({
connectionLimit: 100,
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
});
pool.getConnection((err, connection) => {
if (err) {
throw err;
}
});
/*app.get("/", (req, res) => {
res.render("home");
});*/
const routes = require('./server/routes/route');
app.get('/', routes);
app.post('/', routes);
app.get('/login', routes);
app.post('/login', routes);
app.get("/logout", routes);
app.get('/update', routes);
app.post('/updates', routes);
app.get('/success', routes);
app.get('/failure', routes);
/*
app.get("/update", (req, res) => {
res.render("update");
});
app.get("/login", (req, res) => {
res.render("login");
});
app.get("/success", (req, res) => {
res.render("success");
});
app.get("/failure", (req, res) => {
res.render("failure");
});
app.get('/logout', (req, res)=>{
req.session.destroy(function(err){
if(!err){
console.log('Destroyed session');
}else{
console.log(err);
}
res.redirect('/');
});
});
*/
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});