Refactor namings.
This commit is contained in:
11
server.ts
11
server.ts
@@ -127,29 +127,23 @@ const loggedBodyshopIds = new Set<string>();
|
||||
app.use((req, res, next) => {
|
||||
//Asynchronously check the headers for a bodyshopid. If it exists, write it to a json file in the root directory. Only do this if the bodyshopid has not already been logged once since server start.
|
||||
const bodyshopId = req.headers.bodyshopid as string;
|
||||
|
||||
console.log("*** ~ loggedBodyshopIds:", loggedBodyshopIds);
|
||||
if (bodyshopId && !loggedBodyshopIds.has(bodyshopId)) {
|
||||
loggedBodyshopIds.add(bodyshopId);
|
||||
|
||||
// Asynchronously write to file without blocking the request
|
||||
(async () => {
|
||||
try {
|
||||
const fs = await import("fs/promises");
|
||||
const filePath = path.join(FolderPaths.Root, "config.json");
|
||||
|
||||
let existingIds: string[] = [];
|
||||
try {
|
||||
const fileContent = await fs.readFile(filePath, "utf-8");
|
||||
const fileContent = await fs.readFile(FolderPaths.Config, "utf-8");
|
||||
const configFile = JSON.parse(fileContent);
|
||||
existingIds = configFile.bodyshopIds || [];
|
||||
} catch {
|
||||
// File doesn't exist or is invalid, start with empty array
|
||||
}
|
||||
|
||||
if (!existingIds.includes(bodyshopId)) {
|
||||
existingIds.push(bodyshopId);
|
||||
await fs.writeFile(filePath, JSON.stringify({ bodyshopIds: existingIds }, null, 2));
|
||||
await fs.writeFile(FolderPaths.Config, JSON.stringify({ bodyshopIds: existingIds }, null, 2));
|
||||
logger.info(`Logged new bodyshop ID: ${bodyshopId}`);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -157,7 +151,6 @@ app.use((req, res, next) => {
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user