forked from ShivamJhaa/FoodOrderingWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
59 lines (50 loc) · 1.27 KB
/
server.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
const express = require('express')
const path = require('path')
const mysql = require('mysql')
const app = express()
const dotenv = require('dotenv')
const cookieParser = require('cookie-parser')
dotenv.config({ path: './.env'})
const db = mysql.createConnection({
host: process.env.DATABASE_HOST,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE
})
const publicDirectory = path.join(__dirname, './public')
app.use(express.static(publicDirectory))
app.use(express.urlencoded({extended: false}))
app.use(express.json())
app.use(cookieParser())
app.set('view engine','hbs')
db.connect((err)=>{
if(err){
console.log(err);
}
else{
console.log("mysql connected");
}
})
//Defining routes
app.use('/',require('./routes/pages'))
app.use('/auth',require('./routes/auth'))
app.get('/profile',(req,res)=>{
res.render('profile')
})
app.get('/auth/logout', async (req, res) =>
{
res.clearCookie('jwt');
res.redirect('/login')
})
// exports.logout = async (req,res) => {
// res.clearCookie('jwt');
// res.redirect('/login');
// };
app.listen(3000,(err)=>{
if(err){
console.log(err);
}
else {
console.log('Server is listening at port 3000')
}
})