22 lines
549 B
JavaScript
22 lines
549 B
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function loadMocks(app) {
|
|
const mockDir = path.resolve(__dirname);
|
|
|
|
fs.readdirSync(mockDir).forEach(file => {
|
|
if (file === 'index.js') return;
|
|
const filePath = path.join(mockDir, file);
|
|
delete require.cache[require.resolve(filePath)];
|
|
const routes = require(filePath);
|
|
|
|
Object.entries(routes).forEach(([key, handler]) => {
|
|
const [method, route] = key.split(' ');
|
|
app[method.toLowerCase()](route, handler);
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = { loadMocks };
|
|
|