| |
|
|
| import fs from 'fs'; |
| import path from 'path'; |
|
|
| export default function handler(req, res) { |
| const apiDir = path.join(process.cwd(), 'pages/api'); |
|
|
| try { |
| |
| const files = fs.readdirSync(apiDir); |
|
|
| |
| const jsFiles = files.filter(file => file !== 'apiList.js' && file.endsWith('.js')); |
|
|
| |
| const apiList = []; |
|
|
| |
| for (const file of jsFiles) { |
| const filePath = path.join(apiDir, file); |
| |
| |
| const fileContent = fs.readFileSync(filePath, 'utf-8'); |
| |
| |
| const jsonMatch = fileContent.match(/export\s+const\s+config\s+=\s+({[\s\S]*?})/); |
|
|
| |
| if (jsonMatch && jsonMatch[1]) { |
| console.log(jsonMatch[1]) |
| const config = JSON.parse(jsonMatch[1]); |
| apiList.push({...config }); |
| } |
| } |
|
|
| |
| fs.writeFileSync( |
| path.join(process.cwd(), 'public/apiList.json'), |
| JSON.stringify(apiList, null, 2), |
| ); |
|
|
| |
| res.status(200).json(apiList); |
| } catch (error) { |
| console.error('Error reading API directory:', error); |
| res.status(500).json({ error: 'Internal Server Error' }); |
| } |
| } |
|
|