From a4eabce37a9b127d1e1aaaa17a660aa2dcac1fc2 Mon Sep 17 00:00:00 2001 From: ajnart Date: Sun, 8 Jan 2023 13:11:48 +0900 Subject: [PATCH] Fix not filtering .json files for config --- src/pages/api/configs/[slug].ts | 8 ++++++-- src/pages/api/configs/index.ts | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) 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', ''));