-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (24 loc) · 827 Bytes
/
app.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
//Todo lo relacionado con express
import "dotenv/config";
import mongoose from "mongoose";
import express from "express";
import morgan from "morgan";
import usersRoutes from "./routes/usersRoutes.js";
import ticketsRoutes from "./routes/ticketsRoutes.js";
const app = express();
const DB_URL =
process.env.NODE_ENV === "test"
? "mongodb://localhost:27017/ticketing-db-test"
: process.env.DB_URL || "mongodb://localhost:27017/ticketing-db";
mongoose
.connect(DB_URL)
.then(() => console.log(`Connected to DB: ${DB_URL}`))
.catch((err) => console.error("Failed to connect to MongoDB", err));
app.use(morgan("dev"));
app.use(express.json());
app.get("/ping", (req, res) => {
res.status(200).send("pong");
});
app.use("/api/users", usersRoutes);
app.use("/api/tickets", ticketsRoutes);
export default app;