-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
42 lines (33 loc) · 1003 Bytes
/
index.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
const express = require('express');
const bodyParser = require('body-parser');
const { Author, Book } = require('./sequelize');
const app = express();
app.use(bodyParser.json());
app.get('/api/authors', (req, res) => {
Author.findAll().then(authors => res.json(authors));
});
app.get('/api/books', (req, res) => {
Book.findAll().then(books => res.json(books));
});
app.set('view engine', 'pug');
app.set('views', './views');
app.get('/', function (req, res) {
res.render('index', { title: 'Hey', message: 'Hello there!' })
});
app.get('/login', function (req, res) {
res.render('login', { title: 'Login', message: 'Click to login' })
});
app.post('/login', function (req, res) {
res.redirect('/books');
});
app.get('/books', function (req, res) {
Book.findAll({
include: [{ all: true }]
}).then(books => {
res.render('books', { title: 'Books', books: books });
});
});
const port = 3000;
app.listen(port, () => {
console.log(`Running on http://localhost:${port}`);
});