Middleware can be defined as such
const authCheck = (req: Request, res: Response, next: NextFunction) => {
if (req.headers.Authentication === undefined) {
res.status(401).send('Missing Authentication Header')
return
}
next()
}
In Express, .use() method initializes a middleware (argument 2) in a given path (argument 1).
In the middleware, the next() function will jump to the next middleware or endpoint.
server.use('/customers', authCheck)
server.get('/customers', (req, res) => {
...