agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
39 lines (35 loc) • 998 B
JavaScript
/**
* @file Middleware extractor
* @description Extracts middleware information from route definitions
*/
/**
* Extract middleware information from route context
* @param {string} content - File content
* @param {number} matchIndex - Index of route match
* @returns {Object} Middleware information
*/
function extractMiddleware(content, matchIndex) {
const beforeMatch = content.substring(Math.max(0, matchIndex - 200), matchIndex);
const middlewarePatterns = [
/auth/i,
/cors/i,
/validate/i,
/permission/i,
/rate.*limit/i
];
const detected = [];
middlewarePatterns.forEach(pattern => {
if (pattern.test(beforeMatch)) {
detected.push(pattern.source.replace(/[\\\/\[\](){}.*+?^$|]/g, ''));
}
});
return {
detected,
hasAuth: detected.some(m => m.includes('auth')),
hasCors: detected.some(m => m.includes('cors')),
hasValidation: detected.some(m => m.includes('validate'))
};
}
module.exports = {
extractMiddleware
};