All files / server/routes robots.txt.get.ts

100% Statements 9/9
33.33% Branches 1/3
100% Functions 0/0
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 111x 1x 1x 1x   1x 1x 1x 1x 1x  
export default defineEventHandler(async event => {
    const db = database(event)
    await ready(db)
    const canonical = await db.prepare("SELECT value FROM site_content WHERE `key`='seoCanonicalUrl'").first<{
        value: string
    }>()
    const origin = String(canonical?.value || useRuntimeConfig(event).public.siteUrl || getRequestURL(event).origin).replace(/\/$/, '')
    setHeader(event, 'content-type', 'text/plain; charset=utf-8')
    return `User-agent: *\nAllow: /\nDisallow: /admin\nDisallow: /api/\nDisallow: /compte\nDisallow: /commande\nDisallow: /panier\nSitemap: ${origin}/sitemap.xml\n`
})