-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (38 loc) · 1.06 KB
/
server.js
File metadata and controls
48 lines (38 loc) · 1.06 KB
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
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
// Models
const db = require("./app/models");
const app = express();
let whiteList = [
'http://localhost:8081',
];
let corsOption = {
origin: function (origin, callback) {
if (whiteList.indexOf(origin) !== -1 || !origin) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'))
}
}
};
app.use(cors(corsOption));
// parse requests of content-type - application/json
app.use(bodyParser.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true}));
// Sync database
db.sequelize.sync();
// simple route
app.get("/", (req, res) => {
res.json({
message: "Welcome to ExMySQL"
});
});
// Post Routes
require("./app/routes/post.routes")(app);
// set port, listen for request
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}/`);
});