-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (27 loc) · 989 Bytes
/
server.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
const express = require('express');
const cors = require('cors');
const sequelize = require('./config/database');
const userRoutes = require('./routes/userRoutes');
const nutritionRoutes = require('./routes/nutritionRoutes');
const swaggerUi = require('swagger-ui-express');
const fs = require('fs');
const yaml = require('js-yaml');
require('dotenv').config();
const app = express();
const PORT = process.env.PORT;
app.use(cors());
app.use(express.json());
const swaggerDocument = yaml.load(fs.readFileSync('./docs.yaml', 'utf8'));
app.use('/api/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/api/users', userRoutes);
app.use('/api/nutritions', nutritionRoutes);
sequelize.authenticate()
.then(() => {
console.log('Database connected...');
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});