UNPKG

nuxt

Version:

Nuxt is a free and open-source framework with an intuitive and extendable way to create type-safe, performant and production-grade full-stack web applications and websites with Vue.js.

12 lines (11 loc) 613 B
import { getRequestHeader } from "h3"; export function isJsonRequest(event) { if (hasReqHeader(event, "accept", "text/html")) { return false; } return hasReqHeader(event, "accept", "application/json") || hasReqHeader(event, "user-agent", "curl/") || hasReqHeader(event, "user-agent", "httpie/") || hasReqHeader(event, "sec-fetch-mode", "cors") || event.path.startsWith("/api/") || event.path.endsWith(".json"); } export function hasReqHeader(event, name, includes) { const value = getRequestHeader(event, name); return value && typeof value === "string" && value.toLowerCase().includes(includes); }