-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
78 lines (67 loc) · 1.48 KB
/
server.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
66
67
68
69
70
71
72
73
74
75
76
77
78
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json())
const cors = require('cors')
const corsOptions = {
origin: 'http://localhost:4200',
optionsSuccessStatus: 200
}
app.use(cors(corsOptions))
const db = require('./app/config/db.config.js');
// force: true will drop the table if it already exists
db.sequelize.sync({force: true}).then(() => {
console.log('Drop and Resync with { force: true }');
initial();
});
require('./app/route/customer.route.js')(app);
// Create a Server
var server = app.listen(8080, function () {
let host = server.address().address
let port = server.address().port
console.log("App listening at http://%s:%s", host, port);
})
function initial(){
let customers = [
{
firstname: "Joe",
lastname: "Thomas",
age: 36
},
{
firstname: "Peter",
lastname: "Smith",
age: 18
},
{
firstname: "Lauren",
lastname: "Taylor",
age: 31
},
{
firstname: "Mary",
lastname: "Taylor",
age: 24
},
{
firstname: "David",
lastname: "Moore",
age: 25
},
{
firstname: "Holly",
lastname: "Davies",
age: 27
},
{
firstname: "Michael",
lastname: "Brown",
age: 45
}
]
// Init data -> save to PostgreSQL
const Customer = db.customers;
for (let i = 0; i < customers.length; i++) {
Customer.create(customers[i]);
}
}