-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
47 lines (31 loc) · 1.04 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
const express = require('express')
const mongoose = require('mongoose')
const db = require('./createDB/database')
const path = require('path')
const bodyParser = require('body-parser')
const router = require('./routers/router')
const app = express();
const bodyParserMW = bodyParser.urlencoded({ extended: true })
app.use(express.static(path.join(__dirname, 'static'))) /// built in middelware
// this return ejs
app.set('view engine', 'ejs');
app.set('views', 'views') // default
// Error-handling middleware
app.use((err, req, res, next) => {
if (!err) { return next(); }
res.status(500);
res.send('500: Internal server error');
});
app.use(router) // use router middleware
app.get('/login', (req, res, next) => {
if (req.cookies.id_user === "" || req.cookies.id_user === null) {
res.render('authentication');
} else {
res.redirect('/home')
}
})
app.get('/log_out', (req, res) => {
res.cookie('id_user', "")
res.redirect('/login')
})
app.listen(5000, () => { console.log("Server Is Running") })