small changes
This commit is contained in:
parent
54f6c5c053
commit
51618c8858
@ -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`)
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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);
|
||||
|
||||
|
3
stubs/api/key.js
Normal file
3
stubs/api/key.js
Normal file
@ -0,0 +1,3 @@
|
||||
const TOKEN_KEY = '5frv12e4few3r';
|
||||
|
||||
module.exports = { TOKEN_KEY }
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user