-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (49 loc) · 1.55 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const express = require('express');
const router = express.Router();
const bodyParser = require('body-parser');
const sequelize = require('./utils/database');
require('dotenv').config();
const app = express();
app.use(bodyParser.json()); //application/json
app.use((req,res,next) => {
res.setHeader('Access-Control-Allow-Origin','*');
res.setHeader('Access-Control-Allow-Methods','GET,POST,PUT,PATCH,DELETE');
res.setHeader('Access-Control-Allow-Headers','Content-Type,Authorization');
next();
});
//Routing
app.use('/',router);
require('./routes')(app);
const Post = require('./models/post');
const User = require('./models/user');
User.hasMany(Post);
Post.belongsTo(User);
//Use try...catch
sequelize.authenticate()
try{
console.log('Connection Established Successfully');
//sequelize.sync({force:true})
sequelize.sync()
try{
console.log('Sync to DB with Success');
}
catch(err){
console.log('Sync to DB Error:',err);
}
}catch(err){
console.log('Connection to DB Error:',err);
}
/* sequelize.authenticate()
.then( rec => {
console.log('Connessione Stabilita con Successo');
//sequelize.sync({force:true})
sequelize.sync()
.then(user => {
console.log('Sync al DB con Successo');
}).catch( err => {
console.log('Sync al DB Error:',err);
});
}).catch( err => {
console.log('Connession al DB Error:',err);
}); */
app.listen(process.env.PORT || 81);