diff --git a/src/pages/api/configs/[slug].ts b/src/pages/api/configs/[slug].ts index a4bc6b5f1..2c6a7b399 100644 --- a/src/pages/api/configs/[slug].ts +++ b/src/pages/api/configs/[slug].ts @@ -88,7 +88,9 @@ function Get(req: NextApiRequest, res: NextApiResponse) { } // Loop over all the files in the /data/configs directory - const files = fs.readdirSync('data/configs'); + // Get all the configs in the /data/configs folder + // All the files that end in ".json" + const files = fs.readdirSync('./data/configs').filter((file) => file.endsWith('.json')); // Strip the .json extension from the file name const configs = files.map((file) => file.replace('.json', '')); @@ -134,7 +136,9 @@ function Delete(req: NextApiRequest, res: NextApiResponse) { } // Loop over all the files in the /data/configs directory - const files = fs.readdirSync('data/configs'); + // Get all the configs in the /data/configs folder + // All the files that end in ".json" + const files = fs.readdirSync('./data/configs').filter((file) => file.endsWith('.json')); // Strip the .json extension from the file name const configs = files.map((file) => file.replace('.json', '')); diff --git a/src/pages/api/configs/index.ts b/src/pages/api/configs/index.ts index 07abc7507..f582b7855 100644 --- a/src/pages/api/configs/index.ts +++ b/src/pages/api/configs/index.ts @@ -2,8 +2,9 @@ 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'); + // Get all the configs in the /data/configs folder + // All the files that end in ".json" + const files = fs.readdirSync('./data/configs').filter((file) => file.endsWith('.json')); // Strip the .json extension from the file name const configs = files.map((file) => file.replace('.json', ''));