diff --git a/src/backend/api.js b/src/backend/api.js index 7aeb26a..040f11a 100644 --- a/src/backend/api.js +++ b/src/backend/api.js @@ -1,10 +1,10 @@ import {getConfigValue} from "@brojs/cli"; -const LOCAL = "http://localhost:8099" + getConfigValue("enterfront.api"); -const DEV = "https://dev.bro-js.ru" + getConfigValue("enterfront.api"); +const LOCAL = "http://localhost:8099"; +const DEV = "https://dev.bro-js.ru"; -export const BASE_API_URL = DEV; +export const BASE_API_URL = LOCAL + getConfigValue("enterfront.api"); // fetch(`${BASE_API_URL}/books/list`) diff --git a/stubs/api/auth/index.js b/stubs/api/auth/index.js index ea32017..abfd874 100644 --- a/stubs/api/auth/index.js +++ b/stubs/api/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/stubs/api/change/index.js b/stubs/api/change/index.js index c5e0837..b5d2b7e 100644 --- a/stubs/api/change/index.js +++ b/stubs/api/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/stubs/api/chat/index.js b/stubs/api/chat/index.js index fd1d5cf..ce2f169 100644 --- a/stubs/api/chat/index.js +++ b/stubs/api/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/stubs/api/key.js b/stubs/api/key.js new file mode 100644 index 0000000..d02db5a --- /dev/null +++ b/stubs/api/key.js @@ -0,0 +1,3 @@ +const TOKEN_KEY = '5frv12e4few3r'; + +module.exports = { TOKEN_KEY } \ No newline at end of file diff --git a/stubs/api/middlewares/verify.js b/stubs/api/middlewares/verify.js index bcc653d..e0c462c 100644 --- a/stubs/api/middlewares/verify.js +++ b/stubs/api/middlewares/verify.js @@ -1,13 +1,12 @@ 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]; if (!token) { - return res.status(403).send({ message: 'No token provided' }); + return res.status(401).send({ message: 'No token provided' }); } // Verify token