-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (58 loc) · 2.16 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const winston = require("winston");
const cors = require("cors");
const express = require("express");
//const favicon = require('express-favicon');
const path = require("path");
const mongoose = require("mongoose");
const todos = require("./routes/todos");
const signUp = require("./routes/signUp");
const signIn = require("./routes/signIn");
const users = require("./routes/users");
const posts = require("./routes/posts");
const projects = require("./routes/projects");
const events = require("./routes/events");
const conversations = require("./routes/conversations");
const messages = require("./routes/messages")
winston.exceptions.handle(
new winston.transports.Console({colorize: true, prettyprint: true}),
new winston.transports.File({filename: "uncaughtExceptions.log"})
);
process.on("unhandledRejection", (error) => {
throw error;
});
winston.add(new winston.transports.File({filename: "logfile.log"}));
require("dotenv").config();
const app = express();
// app.use(express.static(path.resolve(__dirname, "../build")));
// app.get("*", function (request, response) {
// response.sendFile(path.resolve(__dirname, "../build", "index.html"));
// });
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cors());
app.use("/api/todos", todos);
app.use("/api/signup", signUp);
app.use("/api/signin", signIn);
app.use("/api/users", users);
app.use("/api/posts", posts);
app.use("/api/projects", projects);
app.use("/api/events", events);
app.use("/api/conversations", conversations);
app.use("/api/messages", messages);
app.get("/", (req, res) => {
res.send("добро пожаловать в API фэт...");
});
const uri = process.env.ATLAS_URI;
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Сервер запущен на порту: ${PORT}...`);
});
mongoose
.connect(uri, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() => console.log("MongoDB соединение установлено..."))
.catch((error) => console.error("MongoDB соединение потеряно:", error.message));