-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
33 lines (26 loc) · 827 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
// app.js
const express = require('express');
const app = express();
const cors = require('cors');
const personsRouter = require('./controllers/persons');
const { requestLogger, unknownEndpoint, errorHandler } = require('./utils/middleware');
const logger = require('./utils/logger');
const config = require('./utils/config');
const mongoose = require('mongoose');
logger.info('Connecting to', config.MONGODB_URI);
mongoose
.connect(config.MONGODB_URI)
.then(() => {
logger.info('Connected to MongoDB');
})
.catch((error) => {
logger.error('Error connecting to MongoDB:', error.message);
});
app.use(cors());
app.use(express.static('dist'));
app.use(express.json());
app.use(requestLogger);
app.use('/api/persons', personsRouter);
app.use(unknownEndpoint);
app.use(errorHandler);
module.exports = app;