From b215e22f53d07c39337ea74861284f938afa76d5 Mon Sep 17 00:00:00 2001 From: Nikolai Petukhov Date: Sat, 12 Oct 2024 11:17:21 +0300 Subject: [PATCH] fixed const key, logs, deleted example --- .vscode/launch.json | 26 ------------------- .../epja-2024-1/enterfront/auth/index.js | 6 +---- .../epja-2024-1/enterfront/change/index.js | 7 +---- .../epja-2024-1/enterfront/chat/index.js | 5 ---- server/routers/epja-2024-1/enterfront/key.js | 3 +++ .../enterfront/middlewares/verify.js | 3 +-- server/routers/epja-2024-1/example/index.js | 26 ------------------- server/routers/epja-2024-1/example/news.json | 25 ------------------ server/routers/epja-2024-1/index.js | 2 -- 9 files changed, 6 insertions(+), 97 deletions(-) delete mode 100644 .vscode/launch.json create mode 100644 server/routers/epja-2024-1/enterfront/key.js delete mode 100644 server/routers/epja-2024-1/example/index.js delete mode 100644 server/routers/epja-2024-1/example/news.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 60cc5a1..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "pwa-node", - "request": "launch", - "name": "Launch Program", - "skipFiles": [ - "/**" - ], - "program": "${workspaceFolder}/server/index.js" - }, - { - "name": "attach", - "type": "pwa-node", - "request": "attach", - "skipFiles": [ - "/**" - ], - "processId": "${command:PickProcess}" - } - ] -} \ No newline at end of file diff --git a/server/routers/epja-2024-1/enterfront/auth/index.js b/server/routers/epja-2024-1/enterfront/auth/index.js index ea32017..abfd874 100644 --- a/server/routers/epja-2024-1/enterfront/auth/index.js +++ b/server/routers/epja-2024-1/enterfront/auth/index.js @@ -3,8 +3,7 @@ const authRouter = require('express').Router(); // For creating tokens const jwt = require('jsonwebtoken'); -require('dotenv').config(); -const TOKEN_KEY = process.env.TOKEN_KEY; +const { TOKEN_KEY } = require('../key') module.exports = authRouter; @@ -15,7 +14,6 @@ const { addUserToDB, getUserFromDB } = require('../db'); // Get a user by its id authRouter.get('/:id', (req, res) => { const user = getUserFromDB(req.params.id); - console.log("Request get in /auth:", req.params.id); if (user) { res.status(200).send({user}); @@ -27,7 +25,6 @@ authRouter.get('/:id', (req, res) => { // For login (authorization) authRouter.post('/login', (req, res) => { const { name, password } = req.body; - console.log("Request login in /auth:", name); const user = getUserFromDB(name); @@ -54,7 +51,6 @@ authRouter.post('/login', (req, res) => { authRouter.post('/reg', (req, res) => { const { name, password, nickname } = req.body; - console.log("Request reg in /auth:", name); const user = getUserFromDB(name); diff --git a/server/routers/epja-2024-1/enterfront/change/index.js b/server/routers/epja-2024-1/enterfront/change/index.js index c5e0837..b5d2b7e 100644 --- a/server/routers/epja-2024-1/enterfront/change/index.js +++ b/server/routers/epja-2024-1/enterfront/change/index.js @@ -2,14 +2,11 @@ const changeRouter = require('express').Router(); module.exports = changeRouter; -const { users, getUserFromDB, deleteUserFromDB, addUserToDB } = require('../db'); - -const jwt = require("jsonwebtoken"); +const { getUserFromDB, deleteUserFromDB, addUserToDB } = require('../db'); changeRouter.post('/nickname', (req, res) => { const { id, newNickname } = req.body; - console.log("Request nickname in /change:", id); const user = getUserFromDB(id); @@ -36,7 +33,6 @@ changeRouter.post('/nickname', (req, res) => { changeRouter.post('/password', (req, res) => { const { id, newPassword } = req.body; - console.log("Request password in /change:", id); const user = getUserFromDB(id); @@ -62,7 +58,6 @@ changeRouter.post('/password', (req, res) => { changeRouter.delete('/:id', (req, res) => { const { id } = req.params; - console.log("Request delete in /change:", id); deleteUserFromDB(id); }); diff --git a/server/routers/epja-2024-1/enterfront/chat/index.js b/server/routers/epja-2024-1/enterfront/chat/index.js index fd1d5cf..ce2f169 100644 --- a/server/routers/epja-2024-1/enterfront/chat/index.js +++ b/server/routers/epja-2024-1/enterfront/chat/index.js @@ -7,7 +7,6 @@ const { getChatFromDB, getUsersChats, addChatToDB, getUserFromDB, chatRouter.get('/item/:id1/:id2', (req, res) => { const { id1, id2 } = req.params; - console.log("Request get in /chat:", id1, id2); if (id1 === id2) { res.status(400).send({message: 'Ids should be different'}); @@ -25,7 +24,6 @@ chatRouter.get('/item/:id1/:id2', (req, res) => { chatRouter.post('/item/:id1/:id2', (req, res) => { const { id1, id2 } = req.params; - console.log("Request post in /chat:", id1, id2); if (id1 === id2) { res.status(400).send({message: 'Ids should be different'}); @@ -58,8 +56,6 @@ chatRouter.post('/item/:id1/:id2', (req, res) => { chatRouter.get('/list/:id', (req, res) => { const { id } = req.params; - console.log("Request get /list in /chat:", id); - const userChats = getUsersChats(id); if (!userChats) { @@ -72,7 +68,6 @@ chatRouter.get('/list/:id', (req, res) => { chatRouter.post('/message/:sender/:receiver', (req, res) => { const { sender, receiver } = req.params; const { message } = req.body; - console.log("Request post /message in /chat:", sender, receiver, message); const chat = getChatFromDB(sender, receiver); diff --git a/server/routers/epja-2024-1/enterfront/key.js b/server/routers/epja-2024-1/enterfront/key.js new file mode 100644 index 0000000..d02db5a --- /dev/null +++ b/server/routers/epja-2024-1/enterfront/key.js @@ -0,0 +1,3 @@ +const TOKEN_KEY = '5frv12e4few3r'; + +module.exports = { TOKEN_KEY } \ No newline at end of file diff --git a/server/routers/epja-2024-1/enterfront/middlewares/verify.js b/server/routers/epja-2024-1/enterfront/middlewares/verify.js index bcc653d..74f585b 100644 --- a/server/routers/epja-2024-1/enterfront/middlewares/verify.js +++ b/server/routers/epja-2024-1/enterfront/middlewares/verify.js @@ -1,7 +1,6 @@ const jwt = require('jsonwebtoken'); -require('dotenv').config(); -const TOKEN_KEY = process.env.TOKEN_KEY; +const { TOKEN_KEY } = require('../key') function verifyToken(req, res, next) { const token = req.headers['authorization']?.split(' ')[1]; diff --git a/server/routers/epja-2024-1/example/index.js b/server/routers/epja-2024-1/example/index.js deleted file mode 100644 index 68094b4..0000000 --- a/server/routers/epja-2024-1/example/index.js +++ /dev/null @@ -1,26 +0,0 @@ -const express = require("express"); -const router = express.Router() - -const waitMiddleware = (req, res, next) => { - setTimeout(() => { - next() - }, 3000) -} - -const listActivated = true -router.get('/list', waitMiddleware, (req, res) => { - req.user - - if (listActivated) { - res.status(200).send(require('./news.json')) - } else { - res.status(500).send() - } -}) - -router.get('/list-activate-toggle', (req, res) => { - listActivated = !listActivated - res.send(listActivated ? 'Activated' : 'Deactivated') -}) - -module.exports = router diff --git a/server/routers/epja-2024-1/example/news.json b/server/routers/epja-2024-1/example/news.json deleted file mode 100644 index 18e0fb1..0000000 --- a/server/routers/epja-2024-1/example/news.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "ok": true, - "data": [ - { - "id": "1", - "name": "Some name 1", - "description": "Some long long long long description" - }, - { - "id": "2", - "name": "Some name 2", - "description": "Some long long long long description" - }, - { - "id": "3", - "name": "Some name 3", - "description": "Some long long long long description" - }, - { - "id": "4", - "name": "Some name 4", - "description": "Some long long long long description" - } - ] -} diff --git a/server/routers/epja-2024-1/index.js b/server/routers/epja-2024-1/index.js index da4ff89..2097192 100644 --- a/server/routers/epja-2024-1/index.js +++ b/server/routers/epja-2024-1/index.js @@ -2,8 +2,6 @@ const express = require('express') const router = express.Router() -router.use('/example', require('./example/index')) router.use('/enterfront', require('./enterfront/index')) - module.exports = router