2022-05-12 19:28:10 +02:00
|
|
|
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', ''));
|
2022-05-12 21:38:21 +02:00
|
|
|
|
2022-05-12 19:28:10 +02:00
|
|
|
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',
|
|
|
|
|
});
|
|
|
|
|
};
|