-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 830 Bytes
/
index.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
const express = require('express');
const morgan = require('morgan');
const app = express();
const PORT = 3000;
/* connect to db */
const { sequelize } = require('./database');
sequelize
.authenticate()
.then(() => {
console.log('MySQL connection has been established successfully.');
})
.catch((error) => {
console.error('Unable to connect to the database:', error);
throw error;
});
/* log requests */
const loggerType = process.env.development === 'true' ? 'dev' : 'common';
app.use(morgan(loggerType, {
skip: function skip(req) {
return req.path.startsWith('/health') || req.path.startsWith('/version');
},
}));
/* all API endpoints */
const apiRoutes = require('./api');
app.use('/api', apiRoutes);
app.listen(PORT, () => console.log(`Example gift code app listening on port ${PORT}!`));