getSiteRobotConfig()

See if the Site is indexable within Nitro.

Introduction

The getSiteRobotConfig() Nitro composable gives you access to the site-wide robots config, allowing you to determine if the site can or can't be indexed and why.

This can be useful for disabling certain SEO features when the environment does not allow for indexing.

API

function getSiteRobotConfig(e: H3Event): { indexable: boolean, hints: string[] }

Arguments

  • e: H3Event: The event object.

Returns

  • indexable: boolean: Whether the site is indexable.
  • hints: string[]: A list of hints as to why the site is or isn't indexable.

Example

server/routes/og.png.ts
import { getSiteRobotConfig } from '#imports'

export default defineEventHandler((e) => {
  const { indexable } = getSiteRobotConfig(e)
  // avoid serving og images if the site is not indexable
  if (!indexable) {
    // ...
  }
})
Did this page help you?