-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (31 loc) · 1007 Bytes
/
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
require("dotenv").config();
const express = require("express");
const sequelize = require("./db.js");
const models = require("./models/models.js");
const cors = require("cors");
const fileUpload = require("express-fileupload");
const router = require("./routes/index.js");
const errorHandler = require("./middleware/ErrorHandlingMiddleware.js");
const path = require("path");
const PORT = process.env.PORT || 8888;
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.static(path.resolve(__dirname, "static")));
app.use(fileUpload({}));
app.use("/api", router);
// Обработка ошибок, последний Middleware
app.use(errorHandler);
app.get("/", (req, res) => {
res.status(200).json({ message: "WORKING!!!" });
});
const start = async () => {
try {
await sequelize.authenticate();
// await sequelize.sync({ alter: true });
app.listen(PORT, () => console.log(`Server started: ${PORT}`));
} catch (e) {
console.log(e);
}
};
start();