refactor: rename blacklist to blocklist (#2157)
Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me> Co-authored-by: fallenbagel <98979876+Fallenbagel@users.noreply.github.com> Co-authored-by: 0xsysr3ll <0xsysr3ll@pm.me> Co-authored-by: gauthier-th <mail@gauthierth.fr>
This commit is contained in:
49
server/middleware/deprecation.ts
Normal file
49
server/middleware/deprecation.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import logger from '@server/logger';
|
||||
import type { NextFunction, Request, Response } from 'express';
|
||||
|
||||
interface DeprecationOptions {
|
||||
oldPath: string;
|
||||
newPath: string;
|
||||
sunsetDate?: string;
|
||||
documentationUrl?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark an API route as deprecated.
|
||||
* @see https://datatracker.ietf.org/doc/html/rfc8594
|
||||
*/
|
||||
export const deprecatedRoute = ({
|
||||
oldPath,
|
||||
newPath,
|
||||
sunsetDate,
|
||||
documentationUrl,
|
||||
}: DeprecationOptions) => {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
logger.warn(
|
||||
`Deprecated API endpoint accessed: ${oldPath} → use ${newPath} instead`,
|
||||
{
|
||||
label: 'API Deprecation',
|
||||
ip: req.ip,
|
||||
userAgent: req.get('User-Agent'),
|
||||
method: req.method,
|
||||
path: req.originalUrl,
|
||||
}
|
||||
);
|
||||
|
||||
res.setHeader('Deprecation', 'true');
|
||||
|
||||
const links: string[] = [`<${newPath}>; rel="successor-version"`];
|
||||
if (documentationUrl) {
|
||||
links.push(`<${documentationUrl}>; rel="deprecation"`);
|
||||
}
|
||||
res.setHeader('Link', links.join(', '));
|
||||
|
||||
if (sunsetDate) {
|
||||
res.setHeader('Sunset', new Date(sunsetDate).toUTCString());
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
||||
|
||||
export default deprecatedRoute;
|
||||
Reference in New Issue
Block a user