-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
41 lines (34 loc) · 1.11 KB
/
index.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
"use strict";
const express = require("express");
const helmet = require("helmet");
const bodyParser = require("body-parser");
const models = require("./models/index");
const port = process.env.PORT || 5000;
const app = express();
app.use(helmet());
app.use(bodyParser.json()); // for parsing application/json
// Serve static files
app.use(express.static(__dirname + "/public"));
console.log('after public')
// Routes assignment
// pricing route
app.use("/api", require("./routes/price"));
console.log('after price api')
// Log unhandled Promise rejections
process.on("unhandledRejection", (reason, p) => {
console.error(`Unhandled Rejection at: Promise ${p} reason: ${reason}`);
});
console.log('after unhandled rejection')
//Handle unknown routes
app.use((req, res) => {
console.error("The request didn't match any endpoint");
return res.status(404).send("404 – Not Found");
});
console.log('before sequalize')
// Connect to the database and then Serve the app
models.sequelize.sync().then(() => {
console.log('sequalize sync')
app.listen(port, () => {
console.log(`App listening on port ${port}!`);
});
});