From b15796e52361bde88da3357383aa9d3ce7b7c561 Mon Sep 17 00:00:00 2001 From: Howard Edwards Date: Wed, 16 Oct 2024 15:13:19 -0400 Subject: [PATCH] Use local auth .txt files in "non-deployed" environments --- server/util/getUsersFromFile.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/server/util/getUsersFromFile.js b/server/util/getUsersFromFile.js index 48296b770..9a979a4d0 100644 --- a/server/util/getUsersFromFile.js +++ b/server/util/getUsersFromFile.js @@ -1,10 +1,22 @@ +const path = require('path'); +const fs = require('fs/promises'); + const getUsersFromFile = async file => { - const response = await fetch( - // This needs to be switched back the commented out path. - // `https://raw.githubusercontent.com/w3c/aria-at-app/main/${file}` - `https://raw.githubusercontent.com/w3c/aria-at-app/development/${file}` - ); - const roleGroupTxt = await response.text(); + const isDeployed = + process.env.ENVIRONMENT === 'sandbox' || + process.env.ENVIRONMENT === 'staging' || + process.env.ENVIRONMENT === 'production'; + + let roleGroupTxt; + if (isDeployed) { + const response = await fetch( + `https://raw.githubusercontent.com/w3c/aria-at-app/development/${file}` + ); + roleGroupTxt = await response.text(); + } else { + const filePath = path.join(__dirname, `../../${file}`); + roleGroupTxt = await fs.readFile(filePath, { encoding: 'utf8' }); + } const linesRaw = roleGroupTxt.split('\n'); const noComments = linesRaw.filter(line => line.substr(0, 1) !== '#'); const noEmpties = noComments.filter(line => line.trim().length > 0);