-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
46 lines (31 loc) · 999 Bytes
/
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
const express = require('express')
const bodyParser = require('body-parser')
const session = require('express-session')
const app = express()
const port = process.env.PORT || 5000
// Static Files
app.use(express.static('public'))
app.use('/css', express.static(__dirname + 'public/css'))
app.use('/img', express.static(__dirname + 'public/img'))
app.use('/js', express.static(__dirname + 'public/js'))
// Templating Engine
app.set('views', './src/views')
app.set('view engine', 'ejs')
app.use(session({
secret: 'secret-key',
resave: false,
saveUninitialized: false,
}))
app.use(bodyParser.urlencoded({ extended : false }))
// Routes
const homeRouter = require('./src/routes/home')
const adminRouter = require('./src/routes/admin')
//user routes
app.use('/', homeRouter)
//admin routes
app.use('/admin', adminRouter)
app.use((req,res)=>{
res.render('404.ejs', {root: __dirname})
})
// Listen on port 5000
app.listen(port, () => console.log(`Listening on port ${port}`))