A minimal Next.js App Router route handler that serves
the JSON sayt.js expects. It mirrors sayt-json.php, so
the front-end usage is unchanged — only the data source differs.
app/api/sayt/route.js— the API route. HandlesGET /api/sayt?query=...and returns the sections/data array.
-
Copy
app/api/sayt/route.jsinto your project at the same path (app/api/sayt/route.js). -
Point the plugin at the route:
<input class="search-box" /> <script src="/sayt.js"></script> <script> sayt(document.querySelector('.search-box'), { src: '/api/sayt', showSectionHeadings: true, includeCSS: true }); </script>
-
Replace the in-file
countriesarray with your real data source — a database query, a search index (PostgresILIKE, Elasticsearch, etc.), or any service that can filter by thequerystring.
- Same contract as the PHP example. The response shape is identical, so everything documented in the main README applies.
- Escaping.
sayt.jsrenders titles and descriptions withinnerHTML, so the route HTML-escapes any user-supplied text it echoes back (the query) and URL-encodes it inside links. Do the same for any user data you return. - CORS. The route sends
Access-Control-Allow-Origin: *so a demo page on a different host can call it. If your page and API share an origin, you can remove those headers. - Pages Router? If your project uses the Pages Router instead, put the same
logic in
pages/api/sayt.jsand respond withres.status(200).json(data).