mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 15:35:55 +01:00
29 lines
847 B
TypeScript
29 lines
847 B
TypeScript
|
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||
|
|
import fs from 'fs';
|
||
|
|
|
||
|
|
function Get(req: NextApiRequest, res: NextApiResponse) {
|
||
|
|
// Loop over all the files in the /data/configs directory
|
||
|
|
const files = fs.readdirSync('data/configs');
|
||
|
|
// Strip the .json extension from the file name
|
||
|
|
const configs = files.map((file) => file.replace('.json', ''));
|
||
|
|
// Return the list of files
|
||
|
|
return res.status(200).json(configs);
|
||
|
|
}
|
||
|
|
|
||
|
|
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||
|
|
// Filter out if the reuqest is a POST or a GET
|
||
|
|
if (req.method === 'POST') {
|
||
|
|
return res.status(405).json({
|
||
|
|
statusCode: 405,
|
||
|
|
message: 'Method not allowed',
|
||
|
|
});
|
||
|
|
}
|
||
|
|
if (req.method === 'GET') {
|
||
|
|
return Get(req, res);
|
||
|
|
}
|
||
|
|
return res.status(405).json({
|
||
|
|
statusCode: 405,
|
||
|
|
message: 'Method not allowed',
|
||
|
|
});
|
||
|
|
};
|