diff --git a/.gitignore b/.gitignore index 3447aa9..7ea34e7 100644 --- a/.gitignore +++ b/.gitignore @@ -103,6 +103,8 @@ dist # TernJS port file .tern-port - # local env files .env*.local + +# config file for BorgWarehouse +config/repo.json \ No newline at end of file diff --git a/config/repo.json b/config/repo.json deleted file mode 100644 index fe51488..0000000 --- a/config/repo.json +++ /dev/null @@ -1 +0,0 @@ -[] diff --git a/pages/api/repo/index.js b/pages/api/repo/index.js index aaa220d..704fb8d 100644 --- a/pages/api/repo/index.js +++ b/pages/api/repo/index.js @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import fs from 'fs'; import path from 'path'; import { authOptions } from '../../../pages/api/auth/[...nextauth]'; import { unstable_getServerSession } from 'next-auth/next'; @@ -17,8 +17,15 @@ export default async function handler(req, res) { //console.log('API call (GET)'); //Find the absolute path of the json directory const jsonDirectory = path.join(process.cwd(), '/config'); - //Read the json data file data.json - let repoList = await fs.readFile( + //Check if the repo.json file exists and initialize it if not. + if (!fs.existsSync(jsonDirectory + '/repo.json')) { + fs.writeFileSync( + jsonDirectory + '/repo.json', + JSON.stringify([]) + ); + } + //Read the file repo.json + let repoList = await fs.promises.readFile( jsonDirectory + '/repo.json', 'utf8' );