- 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
26 lines
660 B
TypeScript
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))
|
|
})
|