This commit is contained in:
QkoSad
2023-08-08 16:02:54 +03:00
commit 0a7a469d56
315 changed files with 426907 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
const jsonServer = require('json-server')
const server = jsonServer.create()
const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()
const validator = (request, response, next) => {
console.log()
const { content } = request.body
if (request.method==='POST' && (!content || content.length<5) ) {
return response.status(400).json({
error: 'too short anecdote, must have length 5 or more'
})
} else {
next()
}
}
server.use(middlewares)
server.use(jsonServer.bodyParser)
server.use(validator)
server.use(router)
server.listen(3001, () => {
console.log('JSON Server is running')
})