-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
47 lines (38 loc) · 1.01 KB
/
Copy pathapp.js
File metadata and controls
47 lines (38 loc) · 1.01 KB
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 volleyball = require('volleyball');
const views = require('./views/index');
const { db, Page } = require('./models');
const path = require('path');
let app = express();
let port = 3000;
app.use(volleyball);
app.use(express.urlencoded());
app.use(express.static(path.join(__dirname, '/public')));
app.use('/users', require('./routes/user.js'));
app.use('/wiki', require('./routes/wiki.js'));
const init = async () => {
try {
await db.sync();
app.listen(port, () => {
console.log(`connected to server on port ${port}`);
});
} catch (error) {
console.error('init error: ', error);
}
}
app.get('/', async (req, res, next) => {
try {
const allPages = await Page.findAll();
res.send(await views.main(allPages));
} catch (error) {
next(error);
}
});
app.get('/:notfound', (req, res, next) => {
res.status(404).send(views.noPage('Invalid URL'));
});
db.authenticate().
then(() => {
console.log('connected to the database');
});
init();