import { NextFunction , Request , Response } from "express" ; import { UTCISODateFromString } from "italia-ts-commons/lib/dates" ; import { ResponseErrorNotFound } from "italia-ts-commons/lib/responses" ; import { log } from "../logger" ; param dueDate export function dueDateMiddleware ( dueDate ) { return ( req , res , next ) => { const now = new Date ( ) ; if ( now . getTime ( ) > dueDate . getTime ( ) ) { log . warn ( `An ${ req . method . toUpperCase ( ) } ${ req . path } request has landed at ${ UTCISODateFromString . encode ( now ) } although it was supposed to expire at ${ UTCISODateFromString . encode ( dueDate ) }.` ) ; ResponseErrorNotFound ( "Expired resource" , "The resource you asked for is no longer available" ) . apply ( res ) ; } else { next ( ) ; } } ; }