Linking backend data to frontend
This commit is contained in:
27
frontend/app/api/big-models/[...path]/route.ts
Normal file
27
frontend/app/api/big-models/[...path]/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export const dynamic = 'force-static';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ path: string[] }> }
|
||||
) {
|
||||
const { path: pathParts } = await params;
|
||||
const fileName = pathParts.join('/');
|
||||
const filePath = path.join(process.cwd(), 'assets', 'big-models', fileName);
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return new Response('Not Found', { status: 404 });
|
||||
}
|
||||
|
||||
const stat = fs.statSync(filePath);
|
||||
const stream = fs.createReadStream(filePath);
|
||||
|
||||
return new Response(stream as unknown as ReadableStream, {
|
||||
headers: {
|
||||
'Content-Length': stat.size.toString(),
|
||||
'Content-Type': 'model/gltf-binary',
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user