-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (32 loc) · 882 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
const express = require('express')
const morgan = require("morgan");
const { db, Page, User } = require('./models/index');
const wikiRouter = require('./routes/wiki');
const userRouter = require('./routes/users');
const app = express();
// To use body parsing middleware
app.use(express.urlencoded({ extended: false }));
// To use morgan
app.use(morgan("dev"));
// To use express.static middleware
app.use(express.static(__dirname + "/public"));
const layout = require('./views/layout')
db.authenticate()
.then(() => {
console.log('Connected to the database');
})
app.use('/wiki', wikiRouter);
app.get('/', (req, res, next) => {
try {
res.redirect('/wiki');
} catch (error) {
next(error);
}
})
const init = async () => {
await db.sync({ force: true });
app.listen(3000, () => {
console.log(`Server is listening on port 3000!`);
});
}
init();