portfolio/server/routes/scores/[...path].ts
Michael Winter 6ffe5aa1fc Add work pages with hash-based modal URLs and proper 404 handling
- Create dedicated /work/[slug] pages with sticky nav
- Use hash URLs (#type|slug) for modals instead of work page URLs
- Make works without items non-clickable on index
- Add server route to return 404 for non-existent score files
2026-03-06 15:08:30 +01:00

26 lines
660 B
TypeScript

import { existsSync, createReadStream } from 'fs'
import { join } from 'path'
import { sendStream } from 'h3'
import { createError } from 'h3'
export default defineEventHandler(async (event) => {
const url = event.path
// Get the filename from the URL
const filename = url.replace('/scores/', '')
// Check if file exists in public/scores/
const filePath = join(process.cwd(), 'public/scores', filename)
if (!existsSync(filePath)) {
throw createError({
statusCode: 404,
statusMessage: 'Not Found'
})
}
// Serve the file
event.node.res.statusCode = 200
return sendStream(event, createReadStream(filePath))
})