-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (35 loc) · 1.06 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
const { PORT } = require("./config/serverConfig");
const {db} = require("./models");
const express = require('express');
const app = express();
const path = require('path');
const http = require('http');
const routes = require('./routes/index');
// middleware
const cors = require('cors');
const corsOptions = require('./config/corsOptions');
const cookieParser = require('cookie-parser');
// parsing request object
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(cookieParser());
// mounting middleware
app.use(cors(corsOptions));
// mounting route handlers
app.use('/', express.static(path.join(__dirname, '/public')));
app.use('/', require('./routes/root'));
app.use('/api', routes);
// start server
db.sequelize
.authenticate()
.then(() => {
console.log("Connection to MySQL DB established");
})
.catch((error) => {
console.log("MYSQL DB connection failed: ", error);
});
db.sequelize.sync({ force: false });
app.listen(PORT, () => {
console.log(`Server running: http://localhost:${PORT}`);
});
module.exports = app;