robots
Writes robots.txt during the build with User-agent wildcard rules and, with sitemap, the absolute sitemap URL.
robots makes meeko build write robots.txt with rules for User-agent: *: its allow and disallow entries (Allow: / if none are set) and, if sitemap is enabled, a Sitemap: line with its absolute URL. It works with all adapters: on Node, Bun, Deno and Workers it is served like any other public file, with an ETag.
Usage#
// meeko.config.ts
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({
site: "https://example.com",
sitemap: true,
robots: { disallow: ["/admin/"] }, // or robots: true
});Type#
readonly robots?: boolean | RobotsConfiginterface RobotsConfig {
readonly allow?: readonly string[]
readonly disallow?: readonly string[]
}Options#
| Option | Type | Default | Description |
|---|---|---|---|
allow |
readonly string[] |
["/"] if there is no disallow |
Allowed prefixes (Allow:). |
disallow |
readonly string[] |
[] |
Disallowed prefixes (Disallow:). |
Each entry starts with /, with no spaces, ? or #. robots: true is equivalent to {}.
Result#
User-agent: *
Disallow: /admin/
Sitemap: https://example.com/sitemap.xmlWith robots: true and no sitemap:
User-agent: *
Allow: /Examples#
A test environment that is not indexed#
import { defineMeekoConfig } from "@meekojs/meeko/framework";
const staging = process.env.DEPLOY_ENV === "staging";
export default defineMeekoConfig({
robots: staging ? { disallow: ["/"] } : true,
});Allowing a folder inside a disallowed one#
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({ robots: { disallow: ["/cuenta/"], allow: ["/cuenta/ayuda/"] } });Common mistakes#
A misspelled field#
export default defineMeekoConfig({ robots: { disalow: ["/admin/"] } as never });meeko dev, meeko build, meeko check and meeko routes stop with …/meeko.config.ts: robots: campo desconocido disalow.
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({ robots: { disallow: ["/admin/"] } });A path without a leading /#
export default defineMeekoConfig({ robots: { disallow: ["admin"] } });…/meeko.config.ts: robots.disallow debe ser un array de cadenas no vacías que empiecen por /.
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({ robots: { disallow: ["/admin"] } });A public/robots.txt#
public/robots.txt and robots: truemeeko build stops with El archivo público robots.txt (de public/ o de un módulo) choca con el que genera la opción robots de meeko.config.ts; quita uno de los dos.
Delete public/robots.txt and declare its rules in robotsNotes#
- Not security.
Disallowis a request to crawlers, not protection: protect/adminwith a session and server middleware. - Origin.
robotswithoutsitemapdoes not needsite. - Specific pages. To prevent a page from being indexed, use
<meta name="robots" content="noindex">withuseSeoMeta; if it is prerendered, it is also excluded from the sitemap.