-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (37 loc) · 1.6 KB
/
app.js
File metadata and controls
49 lines (37 loc) · 1.6 KB
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
if (process.env.NODE_ENV !== "production") {
require("dotenv").config();
}
const express = require("express");
const app = express();
const cors = require("cors");
const ChatInviteController = require("./controllers/ChatInviteController");
const ChatPrivateController = require("./controllers/ChatPrivateController");
const ChatsController = require("./controllers/ChatsController");
const LoginController = require("./controllers/LoginController");
const ChatAiController = require("./controllers/ChatAiController");
const RoomController = require("./controllers/RoomController");
const UserController = require("./controllers/UserController");
const { guardChats } = require("./middlewares/authorization");
app.use(cors());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.post("/login", LoginController.login);
// middleware authentication
const authentication = require("./middlewares/authentication");
app.use(authentication);
//
app.get("/users", UserController.getAllUsers);
app.post("/rooms", RoomController.create);
app.get("/rooms", RoomController.getAll);
app.get("/chats/:RoomId", guardChats, ChatsController.getChats);
app.post("/chats/:RoomId", guardChats, ChatsController.postChat);
//
app.post("/rooms/:RoomId/invitations", ChatInviteController.create);
app.post("/rooms/:RoomId/ai-chats", ChatAiController.create);
app.post("/rooms/:RoomId/summaries", ChatAiController.summarize);
app.post("/rooms/private", ChatPrivateController.create);
// middleware error handler
const errorHandler = require("./middlewares/errorHandler");
app.use(errorHandler);
//
module.exports = app;