-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (49 loc) · 1.4 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
let express = require('express');
let app = express();
let port = process.env.port || 5000;
let bodyParser = require('body-parser');
let nav = [
{
Link:'/Books',
Text: 'Book'
},
{
Link:'/Authors',
Text: 'Author'
}
];
let bookRouter = require('./src/routes/bookRoutes')(nav);
let adminRouter = require('./src/routes/adminRoutes')(nav);
let authRouter = require('./src/routes/authRoutes');
app.use(express.static('public'));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.set('views','./src/views');
app.set('view engine', 'ejs');
app.use('/Books', bookRouter);
app.use('/Admin', adminRouter);
app.use('/auth', authRouter);
app.get('/', (req, res) => {
res.render('index', { title: 'hello from render',
nav: [
{
Link:'/Books',
Text: 'Books'
},
{
Link:'/Authors',
Text: 'Authors'
}]
});
});
// POST /api/users gets JSON bodies
app.post('/api/users', jsonParser, function (req, res) {
if (!req.body) return res.sendStatus(400)
console.log('');
})
app.listen(port, (err) => {
console.log(`running server in ${port}`);
});
// changes in master