-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
34 lines (30 loc) · 998 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
32
33
34
const express = require("express");
const usuariosRouter = require("./routes/usuarios");
const salaoRouter = require("./routes/salao");
const servicosRouter = require("./routes/servicos");
const dotenv = require("dotenv");
const mongoose = require("mongoose");
const morgan = require('morgan');
const app = express();
dotenv.config();
mongoose.connect(process.env.DATABASE, {
autoIndex: true,
});
const db = mongoose.connection;
db.on("error", (error) => {
console.error(error);
});
db.once("open", () => {
console.log("Conexão estabelecida");
});
app.use(express.json());
app.use(morgan('dev')); // Middleware para exibição de logs de requisições no terminal
app.use("/usuarios", usuariosRouter);
app.use("/salao", salaoRouter);
app.use("/servico", servicosRouter);
app.get("/", function (req, res) {
res.status(200).json({ msg: "Seja benvindo ao servidor do Salão" });
});
app.listen(3000, function () {
console.log("Servidor está no ar! Na porta: " + process.env.PORT);
});