api/load-from-fs: always load files from root of api folder

This commit is contained in:
dumbmoron 2024-08-03 09:27:56 +00:00
parent 8e7b63ade6
commit 0e0ad7cb0e
No known key found for this signature in database

View file

@ -1,12 +1,20 @@
import * as fs from "fs";
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = join(
dirname(fileURLToPath(import.meta.url)),
'../../'
);
export function loadJSON(path) {
try {
return JSON.parse(fs.readFileSync(path, 'utf-8'))
return JSON.parse(fs.readFileSync(join(root, path), 'utf-8'))
} catch {
return false
}
}
export function loadFile(path) {
try {
return fs.readFileSync(path, 'utf-8')