-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (32 loc) · 1.14 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
require("dotenv").config();
const express = require("express");
var cors = require("cors");
const morgan = require("morgan");
const path = require("path");
const app = express();
const PORT = process.env.PORT || 5000;
require("./config/mongo_atlas.js"); //BBDD MongoDB conection
//Docs
const swaggerUi = require("swagger-ui-express");
const swaggerDocument = require("./swagger.json");
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use(morgan("combined"));
//Routes
const apiRoutes = require("./routes/api.routes.js");
const userRoutes = require("./routes/user.routes.js");
app.use("/api", apiRoutes);
app.use("/user", userRoutes);
//* Serve static assets in production, must be at this location of this file
if (process.env.NODE_ENV === "production") {
//*Set static folder (VITE --> dist)
app.use(express.static("client/dist"));
app.get("*", (req, res) =>
res.sendFile(path.resolve(__dirname, "client", "dist", "index.html"))
);
}
app.listen(PORT, () => {
console.log(`Reallo Backend listening on PORT ${PORT}`);
});