Skip to content

Commit 92000a7

Browse files
committed
feat: fixing readfiles api routes
1 parent 23ece77 commit 92000a7

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/pages/api/readfiles.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@ import path from "path";
66

77
const handler = (req: NextApiRequest, res: NextApiResponse) => {
88
try {
9-
const __next__base__dirname = __dirname.split(".next")[0] as string;
10-
let contentDir = path.join(CONTENT_PATH);
11-
if (process.env.NODE_ENV === "production") {
12-
contentDir = path.join(__next__base__dirname, CONTENT_PATH);
13-
}
14-
const directories = fs.readdirSync(path.join(contentDir));
9+
const dir = path.resolve("./", CONTENT_PATH);
10+
const directories = fs.readdirSync(dir);
1511
const lessons: object[] = [];
1612
directories.reverse().map((folder) => {
17-
if (fs.lstatSync(path.join(contentDir, folder)).isDirectory()) {
18-
fs.readdirSync(path.join(contentDir, folder)).map((file) => {
19-
if (
20-
!fs.lstatSync(path.join(contentDir, folder, file)).isDirectory()
21-
) {
13+
if (fs.lstatSync(path.join(dir, folder)).isDirectory()) {
14+
fs.readdirSync(path.join(dir, folder)).map((file) => {
15+
if (!fs.lstatSync(path.join(dir, folder, file)).isDirectory()) {
2216
const markdownWithMeta = fs.readFileSync(
23-
path.join(contentDir, folder, file),
17+
path.join(dir, folder, file),
2418
"utf-8",
2519
);
2620

0 commit comments

Comments
 (0)