forked from wecode-bootcamp-korea/38-2nd-WeFrip-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (33 loc) · 925 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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const morgan =require('morgan');
const appDataSource = require('./models/dataSource');
const routes = require('./routes');
const { globalErrorHandler } = require('./utils/error');
const app = express();
app.use(cors());
app.use(morgan('combined'));
app.use(express.json());
app.use(routes);
app.use(globalErrorHandler);
app.get('/ping', (req, res) => {
res.json({ message: 'pong' });
});
const PORT = process.env.PORT;
const start = async () => {
await appDataSource.initialize()
.then(() => {
console.log('Data Source has been initialized');
})
.catch(() => {
console.log('Errors occurred in Data Source initializing');
appDataSource.destroy();
})
try {
app.listen(PORT, () => console.log(`Server is listening on ${PORT}`));
} catch (err) {
console.error(err);
}
}
start();