forked from Marcosbit93/Back-Klimty
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (26 loc) · 834 Bytes
/
Copy pathserver.js
File metadata and controls
32 lines (26 loc) · 834 Bytes
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
const express = require("express");
const { port } = require("./config/index");
const app = express();
const db = require("./db");
const morgan = require("morgan");
const cors = require("cors");
const { Artist, Product, Cart, User, Checkout } = require("./models");
const routes = require("./routes");
var corsOptions = {
origin: 'http://localhost:3000',
credentials: true,
};
app.use(cors(corsOptions)); // esta librería es para poder trabajar front con back en localhost
app.use(morgan("dev"));
app.use(express.json());
// Express Routing
app.use("/api", routes);
// ERROR MIDDLEWARE
app.use(function (err, req, res, next) {
console.error(err, err.stack);
res.status(500).send(err);
});
db.sync({ force: false }).then(() => {
app.listen(port, () => console.log(`SERVER ON PORT: ${port}`));
});
module.exports = app;