DONE AGAIN
This commit is contained in:
@@ -1,20 +1,32 @@
|
||||
import { Router } from 'express'
|
||||
import { addNote } from './methods/post.js'
|
||||
import { getAllNotes, getSingleNote, getStats, setForbidden } from './methods/get.js'
|
||||
import { getAllNotes, getSingleNote, getStats } from './methods/get.js'
|
||||
import { editNote } from './methods/patch.js'
|
||||
import { deleteNote } from './methods/delete.js'
|
||||
import { id as validate } from '../services/ValidationService.js'
|
||||
import { id as validate } from '../services/ValidationService.js'
|
||||
import { idOnlySchema, newNoteSchema, updateNoteSchema } from '../repositories/schema.js'
|
||||
import { setResp403 } from '../helpers/http.js'
|
||||
|
||||
/**
|
||||
*
|
||||
* @param req
|
||||
* @param res
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const setForbidden = async (req, res) => {
|
||||
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress
|
||||
res.status(403).json(setResp403(`You are not allowed to access the resource. Your IP is ${ip}`))
|
||||
}
|
||||
|
||||
const router = new Router()
|
||||
|
||||
router.get('/notes(\/|)$/', getAllNotes)
|
||||
router.get('/notes\/stats(\/|)$/', getStats)
|
||||
router.get('/notes/:id([0-9]{1,4})$/', validate( idOnlySchema ), getSingleNote) // e.g. also notes with `0x1a` => id = 26 will be affected
|
||||
router.get('/notes/:id([0-9]{1,4})$/', validate(idOnlySchema), getSingleNote) // e.g. also notes with `0x1a` => id = 26 will be affected
|
||||
router.get('*', setForbidden)
|
||||
|
||||
router.post('/notes(\/|)$/', validate( newNoteSchema ), addNote)
|
||||
router.patch('/notes/:id([0-9]{1,4})$/', validate( updateNoteSchema ), editNote)
|
||||
router.delete('/notes/:id([0-9]{1,4})$/', validate( idOnlySchema ), deleteNote)
|
||||
router.post('/notes(\/|)$/', validate(newNoteSchema), addNote)
|
||||
router.patch('/notes/:id([0-9]{1,4})$/', validate(updateNoteSchema), editNote)
|
||||
router.delete('/notes/:id([0-9]{1,4})$/', validate(idOnlySchema), deleteNote)
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user