-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (27 loc) · 888 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
const config = require('./utils/config');
const express = require('express');
const app = express();
const blogsRouter = require('./controllers/blogs');
const usersRouter = require('./controllers/users');
const loginRouter = require('./controllers/login');
const logger = require('./utils/logger');
const mongoose = require('mongoose');
const middleware = require('./utils/middleware');
// 连接数据库
const mongoUrl = config.MONGODB_URI;
logger.info('connecting to', mongoUrl);
mongoose
.connect(mongoUrl, { useNewUrlParser: true, useUnifiedTopology: true } )
.then(() => {
logger.info('connected to MogoDB');
})
.catch(err => {
logger.error(err.message);
});
app.use(express.json());
app.use('/api/blogs', blogsRouter);
app.use('/api/users', usersRouter);
app.use('/api/login', loginRouter);
app.use(middleware.errorHandler);
// 导出app
module.exports = app;