Skip to content

Commit

Permalink
Add cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
avi-friedman-IL committed Jun 20, 2024
1 parent 06082c8 commit c3f4d58
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
15 changes: 15 additions & 0 deletions logs/backend.log
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,18 @@
19.6.2024, 23:41:44 - INFO - Server listening on port http://127.0.0.1:3030/
19.6.2024, 23:44:31 - INFO - Server listening on port http://127.0.0.1:3030/
19.6.2024, 23:46:37 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 10:31:09 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 10:46:11 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 10:59:34 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 11:04:59 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 11:07:49 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 13:22:33 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 13:22:36 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 13:29:49 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 13:30:56 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 13:33:06 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 13:34:29 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 13:40:16 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 13:42:18 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 13:43:52 - INFO - Server listening on port http://127.0.0.1:3030/
20.6.2024, 14:00:01 - INFO - Server listening on port http://127.0.0.1:3030/
2 changes: 2 additions & 0 deletions public/services/bug.service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { request } from "express"

const BASE_URL = '/api/bug'

export const bugService = {
Expand Down
12 changes: 7 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ app.get('/api/bug', (req, res) => {
})

app.get('/api/bug/:id', (req, res) => {
var visitedBugs = req.cookies.visitedBugs || 0
res.cookie('visitedBugs', ++visitedBugs, { maxAge: 7000 })
console.log('req.cookies:', req.cookies)
const { id } = req.params

var visitedBugs = req.cookies.visitedBugs || []
if (visitedBugs.length >= 3) res.status(401).send('You cannot access the bug, wait!')
if (!visitedBugs.includes(id)) visitedBugs.push(id)
res.cookie('visitedBugs', visitedBugs, { maxAge: 7000 })

bugService.getById(id).then(bug => res.send(bug))
})

Expand All @@ -45,7 +47,7 @@ app.put('/api/bug/:id', (req, res) => {
description: description || '',
severity: +severity || 0,
createdAt: +createdAt || Date.now(),
labels: labels,
labels: labels || [],
}

bugService.save(bugToSave).then(savedBug => res.send(savedBug))
Expand All @@ -58,7 +60,7 @@ app.post('/api/bug/', (req, res) => {
description: description || '',
severity: +severity || 0,
createdAt: +createdAt || Date.now(),
labels: labels,
labels: labels || [],
}

bugService.save(bugToSave).then(savedBug => res.send(savedBug))
Expand Down

0 comments on commit c3f4d58

Please sign in to comment.