forked from xanderbakx/wikistack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (44 loc) · 977 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
47
48
49
50
51
52
53
const express = require("express");
const morgan = require("morgan");
const { db, Page, User } = require("./models");
const users = require('./routes/users')
const wiki = require('./routes/wiki')
const bodyParser = require("body-parser");
const {
addPage,
editPage,
main,
userList,
userPages,
wikiPage,
} = require("./views/index");
db.authenticate().then(() => {
console.log("connected to the database");
});
const app = express();
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(morgan("dev"));
app.get("/", (req, res) => {
res.redirect('/wiki')
})
app.get("/", (req, res) => {
res.send(main(""));
});
app.use('/wiki', require('./routes/wiki'));
const sync = async () => {
try {
await Page.sync({
force: true,
});
await User.sync({
force: true,
});
await db.close();
} catch (error) {
await db.close();
console.log(error);
}
};
sync();
app.listen(3000);