fixed const key, logs, deleted example
This commit is contained in:
parent
f13ae33cb4
commit
b215e22f53
26
.vscode/launch.json
vendored
26
.vscode/launch.json
vendored
@ -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": [
|
|
||||||
"<node_internals>/**"
|
|
||||||
],
|
|
||||||
"program": "${workspaceFolder}/server/index.js"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "attach",
|
|
||||||
"type": "pwa-node",
|
|
||||||
"request": "attach",
|
|
||||||
"skipFiles": [
|
|
||||||
"<node_internals>/**"
|
|
||||||
],
|
|
||||||
"processId": "${command:PickProcess}"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -3,8 +3,7 @@ const authRouter = require('express').Router();
|
|||||||
// For creating tokens
|
// For creating tokens
|
||||||
const jwt = require('jsonwebtoken');
|
const jwt = require('jsonwebtoken');
|
||||||
|
|
||||||
require('dotenv').config();
|
const { TOKEN_KEY } = require('../key')
|
||||||
const TOKEN_KEY = process.env.TOKEN_KEY;
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = authRouter;
|
module.exports = authRouter;
|
||||||
@ -15,7 +14,6 @@ const { addUserToDB, getUserFromDB } = require('../db');
|
|||||||
// Get a user by its id
|
// Get a user by its id
|
||||||
authRouter.get('/:id', (req, res) => {
|
authRouter.get('/:id', (req, res) => {
|
||||||
const user = getUserFromDB(req.params.id);
|
const user = getUserFromDB(req.params.id);
|
||||||
console.log("Request get in /auth:", req.params.id);
|
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
res.status(200).send({user});
|
res.status(200).send({user});
|
||||||
@ -27,7 +25,6 @@ authRouter.get('/:id', (req, res) => {
|
|||||||
// For login (authorization)
|
// For login (authorization)
|
||||||
authRouter.post('/login', (req, res) => {
|
authRouter.post('/login', (req, res) => {
|
||||||
const { name, password } = req.body;
|
const { name, password } = req.body;
|
||||||
console.log("Request login in /auth:", name);
|
|
||||||
|
|
||||||
const user = getUserFromDB(name);
|
const user = getUserFromDB(name);
|
||||||
|
|
||||||
@ -54,7 +51,6 @@ authRouter.post('/login', (req, res) => {
|
|||||||
|
|
||||||
authRouter.post('/reg', (req, res) => {
|
authRouter.post('/reg', (req, res) => {
|
||||||
const { name, password, nickname } = req.body;
|
const { name, password, nickname } = req.body;
|
||||||
console.log("Request reg in /auth:", name);
|
|
||||||
|
|
||||||
const user = getUserFromDB(name);
|
const user = getUserFromDB(name);
|
||||||
|
|
||||||
|
@ -2,14 +2,11 @@ const changeRouter = require('express').Router();
|
|||||||
|
|
||||||
module.exports = changeRouter;
|
module.exports = changeRouter;
|
||||||
|
|
||||||
const { users, getUserFromDB, deleteUserFromDB, addUserToDB } = require('../db');
|
const { getUserFromDB, deleteUserFromDB, addUserToDB } = require('../db');
|
||||||
|
|
||||||
const jwt = require("jsonwebtoken");
|
|
||||||
|
|
||||||
|
|
||||||
changeRouter.post('/nickname', (req, res) => {
|
changeRouter.post('/nickname', (req, res) => {
|
||||||
const { id, newNickname } = req.body;
|
const { id, newNickname } = req.body;
|
||||||
console.log("Request nickname in /change:", id);
|
|
||||||
|
|
||||||
const user = getUserFromDB(id);
|
const user = getUserFromDB(id);
|
||||||
|
|
||||||
@ -36,7 +33,6 @@ changeRouter.post('/nickname', (req, res) => {
|
|||||||
|
|
||||||
changeRouter.post('/password', (req, res) => {
|
changeRouter.post('/password', (req, res) => {
|
||||||
const { id, newPassword } = req.body;
|
const { id, newPassword } = req.body;
|
||||||
console.log("Request password in /change:", id);
|
|
||||||
|
|
||||||
const user = getUserFromDB(id);
|
const user = getUserFromDB(id);
|
||||||
|
|
||||||
@ -62,7 +58,6 @@ changeRouter.post('/password', (req, res) => {
|
|||||||
|
|
||||||
changeRouter.delete('/:id', (req, res) => {
|
changeRouter.delete('/:id', (req, res) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
console.log("Request delete in /change:", id);
|
|
||||||
|
|
||||||
deleteUserFromDB(id);
|
deleteUserFromDB(id);
|
||||||
});
|
});
|
||||||
|
@ -7,7 +7,6 @@ const { getChatFromDB, getUsersChats, addChatToDB, getUserFromDB,
|
|||||||
|
|
||||||
chatRouter.get('/item/:id1/:id2', (req, res) => {
|
chatRouter.get('/item/:id1/:id2', (req, res) => {
|
||||||
const { id1, id2 } = req.params;
|
const { id1, id2 } = req.params;
|
||||||
console.log("Request get in /chat:", id1, id2);
|
|
||||||
|
|
||||||
if (id1 === id2) {
|
if (id1 === id2) {
|
||||||
res.status(400).send({message: 'Ids should be different'});
|
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) => {
|
chatRouter.post('/item/:id1/:id2', (req, res) => {
|
||||||
const { id1, id2 } = req.params;
|
const { id1, id2 } = req.params;
|
||||||
console.log("Request post in /chat:", id1, id2);
|
|
||||||
|
|
||||||
if (id1 === id2) {
|
if (id1 === id2) {
|
||||||
res.status(400).send({message: 'Ids should be different'});
|
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) => {
|
chatRouter.get('/list/:id', (req, res) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
|
||||||
console.log("Request get /list in /chat:", id);
|
|
||||||
|
|
||||||
const userChats = getUsersChats(id);
|
const userChats = getUsersChats(id);
|
||||||
|
|
||||||
if (!userChats) {
|
if (!userChats) {
|
||||||
@ -72,7 +68,6 @@ chatRouter.get('/list/:id', (req, res) => {
|
|||||||
chatRouter.post('/message/:sender/:receiver', (req, res) => {
|
chatRouter.post('/message/:sender/:receiver', (req, res) => {
|
||||||
const { sender, receiver } = req.params;
|
const { sender, receiver } = req.params;
|
||||||
const { message } = req.body;
|
const { message } = req.body;
|
||||||
console.log("Request post /message in /chat:", sender, receiver, message);
|
|
||||||
|
|
||||||
const chat = getChatFromDB(sender, receiver);
|
const chat = getChatFromDB(sender, receiver);
|
||||||
|
|
||||||
|
3
server/routers/epja-2024-1/enterfront/key.js
Normal file
3
server/routers/epja-2024-1/enterfront/key.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
const TOKEN_KEY = '5frv12e4few3r';
|
||||||
|
|
||||||
|
module.exports = { TOKEN_KEY }
|
@ -1,7 +1,6 @@
|
|||||||
const jwt = require('jsonwebtoken');
|
const jwt = require('jsonwebtoken');
|
||||||
|
|
||||||
require('dotenv').config();
|
const { TOKEN_KEY } = require('../key')
|
||||||
const TOKEN_KEY = process.env.TOKEN_KEY;
|
|
||||||
|
|
||||||
function verifyToken(req, res, next) {
|
function verifyToken(req, res, next) {
|
||||||
const token = req.headers['authorization']?.split(' ')[1];
|
const token = req.headers['authorization']?.split(' ')[1];
|
||||||
|
@ -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
|
|
@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -2,8 +2,6 @@ const express = require('express')
|
|||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
|
|
||||||
router.use('/example', require('./example/index'))
|
|
||||||
router.use('/enterfront', require('./enterfront/index'))
|
router.use('/enterfront', require('./enterfront/index'))
|
||||||
|
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
Loading…
Reference in New Issue
Block a user