-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (32 loc) · 919 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
const express = require('express');
const bodyParser = require('body-parser');
require('dotenv').config()
const port = 3000;
const morgan = require('morgan');
const sequelize = require('./config/database');
const app = express();
app.use(bodyParser.json());
app.use(express.static('public'));
app.use(morgan('combined'));
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader(
'Access-Control-Allow-Methods',
'OPTIONS, GET, POST, PUT, PATCH, DELETE'
);
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
next();
});
require('./router.js')(app);
app.use('/uploads', express.static('uploads'));
app.get("/", (req, res) => {
res.json({ message: "Welcome to this website" });
});
sequelize
.sync()
.then(result => {
app.listen(port);
})
.catch(err => {
console.log(err);
});