feat: v0.1.0 — scaffold + MapLibre map with EU airports
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { promises as fs } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
// Serves maplibre-gl dist files (worker + its relative imports) straight from
|
||||
// node_modules so they always match the installed version. MapLibre cannot derive
|
||||
// working URLs for these when bundled by Turbopack/webpack, and the worker script
|
||||
// uses a relative import ("./maplibre-gl-shared.mjs") that must resolve against
|
||||
// this same prefix.
|
||||
export async function GET(_req: Request, ctx: { params: Promise<{ file: string }> }) {
|
||||
const { file } = await ctx.params;
|
||||
if (!/^[\w.-]+\.mjs$/.test(file)) return new Response('not found', { status: 404 });
|
||||
try {
|
||||
const body = await fs.readFile(
|
||||
path.join(process.cwd(), 'node_modules', 'maplibre-gl', 'dist', file),
|
||||
);
|
||||
return new Response(body, { headers: { 'content-type': 'text/javascript' } });
|
||||
} catch {
|
||||
return new Response('not found', { status: 404 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user