mirror of
https://github.com/fabrice404/olympics-calendar.git
synced 2025-12-13 06:39:47 +00:00
25 lines
695 B
TypeScript
25 lines
695 B
TypeScript
import { promises as fs } from "fs";
|
|
import { NextResponse } from "next/server";
|
|
import path from "path";
|
|
|
|
const DATA_FOLDER = path.resolve("data");
|
|
|
|
export async function GET(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ slug?: string[] | undefined }> }
|
|
): Promise<NextResponse> {
|
|
try {
|
|
const { slug } = await params || [];
|
|
const filePath = slug ? path.join(DATA_FOLDER, ...slug) : null;
|
|
if (!filePath) throw new Error()
|
|
|
|
const content = await fs.readFile(filePath);
|
|
if (!content) throw new Error()
|
|
|
|
return new NextResponse(content, { status: 200 });
|
|
} catch (ex) {
|
|
console.log(ex);
|
|
return new NextResponse("File not found", { status: 404 });
|
|
}
|
|
}
|