Skip to content

Commit a3aa4eb

Browse files
committed
feat: hack for using fs in api routes
1 parent 7962d4e commit a3aa4eb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/pages/api/readfiles.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { type NextApiRequest, type NextApiResponse } from "next";
55
import path from "path";
66

77
const handler = (req: NextApiRequest, res: NextApiResponse) => {
8-
const contentDir = path.join(CONTENT_PATH);
8+
const __next__base__dirname = __dirname.split(".next")[0] as string;
9+
let contentDir = path.join(CONTENT_PATH);
10+
if (process.env.NODE_ENV === "production") {
11+
contentDir = path.join(__next__base__dirname, CONTENT_PATH);
12+
}
913
const directories = fs.readdirSync(path.join(contentDir));
1014
const lessons: object[] = [];
1115
directories.reverse().map((folder) => {

0 commit comments

Comments
 (0)