Files
FileHost/server/middleware/00-host-isolation.ts
T
2026-10-17 16:09:31 +08:00

23 lines
689 B
TypeScript

import {
shouldBlockImageHostRequest,
shouldBlockVideoHostRequest,
shouldBlockFileHostRequest,
shouldBlockSiteHostImageRequest,
shouldBlockUnknownHostRequest
} from '../utils/host-isolation'
const HOST_ISOLATION_CACHE_CONTROL = 'private, no-cache, max-age=0'
export default defineEventHandler((event) => {
if (
shouldBlockUnknownHostRequest(event)
|| shouldBlockImageHostRequest(event)
|| shouldBlockVideoHostRequest(event)
|| shouldBlockFileHostRequest(event)
|| shouldBlockSiteHostImageRequest(event)
) {
setHeader(event, 'Cache-Control', HOST_ISOLATION_CACHE_CONTROL)
throw createError({ statusCode: 404, statusMessage: 'Not Found' })
}
})