-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (27 loc) · 905 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
const config = require("./utils/config");
const express = require("express");
const app = express();
const cors = require("cors");
const playersRouter = require("./controllers/players");
const usersRouter = require("./controllers/users");
const middleware = require("./utils/middleware.js");
const logger = require("./utils/logger");
const mongoose = require("mongoose");
logger.info("connecting to", config.MONGODB_URI);
mongoose
.connect(config.MONGODB_URI)
.then(() => {
logger.info("connected to MongoDB");
})
.catch((error) => {
logger.error("error connection to MongoDB:", error.message);
});
app.use(cors());
//app.use(express.static("build"));
app.use(express.json());
app.use(middleware.requestLogger);
app.use("/api/users", usersRouter);
app.use("/api/players", playersRouter);
app.use(middleware.unknownEndpoint);
app.use(middleware.errorHandler);
module.exports = app;