mirror of
https://github.com/sasjs/server.git
synced 2026-01-11 00:10:06 +00:00
chore: wip replicating folders api
This commit is contained in:
29
api/src/middlewares/header.ts
Normal file
29
api/src/middlewares/header.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Request, Response } from 'express'
|
||||
|
||||
export const verifyAcceptHeader = (req: Request, res: Response) => {
|
||||
const acceptHeader = req.headers.accept
|
||||
|
||||
if (!acceptHeader) {
|
||||
return res.status(406).json(headerIsNotPresentMessage('Accept'))
|
||||
} else if (acceptHeader !== 'application/json') {
|
||||
return res.status(406).json(headerIsNotValidMessage('Accept'))
|
||||
}
|
||||
}
|
||||
|
||||
export const verifyContentTypeHeader = (req: Request, res: Response) => {
|
||||
const contentTypeHeader = req.headers['content-type']
|
||||
|
||||
if (!contentTypeHeader) {
|
||||
return res.status(406).json(headerIsNotPresentMessage('Content-Type'))
|
||||
} else if (contentTypeHeader !== 'application/json') {
|
||||
return res.status(406).json(headerIsNotValidMessage('Content-Type'))
|
||||
}
|
||||
}
|
||||
|
||||
export const headerIsNotPresentMessage = (header: string) => ({
|
||||
message: `${header} header is not present.`
|
||||
})
|
||||
|
||||
export const headerIsNotValidMessage = (header: string) => ({
|
||||
message: `${header} header is not valid.`
|
||||
})
|
||||
Reference in New Issue
Block a user